d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Relational Database Design > For Inventory With Configurable Items
Add Reply New Topic New Poll
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Sep 11 2013 04:26pm
Hey guys/gals,

I was wondering if anybody has ever built a relational database to track inventory with configurable options?
If so, would you mind sharing some of your database structure.

The reason I ask, a project was recently dumped on me at work.
I have experience building relational databases, however this one is pretty complex.
Below I will briefly explain what our inventory scenario..

We have 3 types of computers
- Tablets
- Laptops
- Convertible Tables (Laptop / Tablet hybrids)

Each "category" of computer has several "sub-categories"
Tablets
- Super Tablet
- Mobile Tablet

Each "sub-category" has even more sub-categories
Super Tablet
- Super Tablet ST-01
- Super Tablet ST-02

Each "sub-sub-category" can be specifically configured
Super Tablet ST-02
- 4 GB Ram
- 500GB 7200RPM HDD
Super Tablet ST-02
- 16GB Ram
- 1TB 7200RPM HDD

I know that high "highest" category will have item specifics such as..
- Serial Number
- Item Condition
- Item Physical Location

I would like to be able to query things such as..
- Total number of tablets
- Total number of Super Tablets
- Total number of Super Tablet ST-01
- Average cost of Tablets
- Average cost of Super Tablets
- Average cost of Super Tablets ST-02
- So on and so forth

So, what I was wondering is if anybody could help me with the actual relationships here..
I would like to keep my database tables normalized to "3rd Normal Form" at least..

Thank for any and all advice.

Don't worry if this is too long..
Even TL;DR responses that contribute information related to highly detailed relation databases will be appreciated.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 11 2013 05:33pm
if you know there's a fixed number of subcategory levels and they're all related, you can make a separate table for each one. if you're not convinced, then use a single table and linked-list it.
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Sep 11 2013 07:35pm
Quote (carteblanche @ Sep 11 2013 06:33pm)
if you know there's a fixed number of subcategory levels and they're all related, you can make a separate table for each one. if you're not convinced, then use a single table and linked-list it.


I agree with this
Member
Posts: 237
Joined: Aug 6 2011
Gold: 6,026.00
Sep 11 2013 08:32pm
Wouldn't simply using an extra table that keeps count of the amount of each computer be enough? It seems that's all you'd need for the bulk of your statistical queries. All update operation could be performed through a class that would maintain the counter table programmatically.

As for more complicated queries, is the development cost of a relational db scheme outweighed by the size of your db or the frequency of such queries over parsing the full db at application spawn?
Member
Posts: 30,717
Joined: Sep 19 2007
Gold: 254.00
Sep 11 2013 11:46pm
Quote (carteblanche @ 11 Sep 2013 17:33)
if you know there's a fixed number of subcategory levels and they're all related, you can make a separate table for each one. if you're not convinced, then use a single table and linked-list it.


no
bad
that makes for awful queries
you clearly don't know what you're talking about
here's my initial thought, not fully thought through w.r.t normalization and everything (I think it's 3nf anyways)

Code
table computer-types
id, type

table computer-category
id, category, typeId ref computer-types

table computer-models
id, name, category ref computer-category

table specs
id, modelId ref computer-models, other info goes here

note: for specs, you could potentially be referencing yet more tables containing part ids and specs for components


so computer-types contains (1,"Tablet")
computer-categories would contain (1,"SuperTablet",1) (2, "weakTablet", 1)
computer-models would contain (1,"Super Tablet - 1",1) (2, "Super Tablet - 2", 1) (3, "punyTablet", 2)
specs would contain (1,1,"500gb hd") (2,1, "750gb hd") (3, 2, "500gb hd") (4,3, "100gb hd")


Quote (flyinggoat @ 11 Sep 2013 20:32)
Wouldn't simply using an extra table that keeps count of the amount of each computer be enough? It seems that's all you'd need for the bulk of your statistical queries. All update operation could be performed through a class that would maintain the counter table programmatically.

As for more complicated queries, is the development cost of a relational db scheme outweighed by the size of your db or the frequency of such queries over parsing the full db at application spawn?


If he was at the level where an additional cache count table was necessary he wouldn't be asking for help here.
If you use a properly designed schema like mine, querying those things is trivial.

This post was edited by J_B on Sep 11 2013 11:50pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 12 2013 12:06am
Quote (J_B @ Sep 12 2013 01:46am)
no
bad
that makes for awful queries
you clearly don't know what you're talking about
here's my initial thought, not fully thought through w.r.t normalization and everything (I think it's 3nf anyways)

Code
table computer-types
id, type

table computer-category
id, category, typeId ref computer-types

table computer-models
id, name, category ref computer-category

table specs
id, modelId ref computer-models, other info goes here

note: for specs, you could potentially be referencing yet more tables containing part ids and specs for components


so computer-types contains (1,"Tablet")
computer-categories would contain (1,"SuperTablet",1) (2, "weakTablet", 1)
computer-models would contain (1,"Super Tablet - 1",1) (2, "Super Tablet - 2", 1) (3, "punyTablet", 2)
specs would contain (1,1,"500gb hd") (2,1, "750gb hd") (3, 2, "500gb hd") (4,3, "100gb hd")




> you say separate tables per level is terrible
> then give design with separate tables per level

teh fook?
Member
Posts: 2,478
Joined: Jan 4 2007
Gold: 7,545.00
Sep 12 2013 07:07am
Quote (J_B @ Sep 11 2013 11:46pm)
no
bad
that makes for awful queries
you clearly don't know what you're talking about
here's my initial thought, not fully thought through w.r.t normalization and everything (I think it's 3nf anyways)

Code
table computer-types
id, type

table computer-category
id, category, typeId ref computer-types

table computer-models
id, name, category ref computer-category

table specs
id, modelId ref computer-models, other info goes here

note: for specs, you could potentially be referencing yet more tables containing part ids and specs for components


so computer-types contains (1,"Tablet")
computer-categories would contain (1,"SuperTablet",1) (2, "weakTablet", 1)
computer-models would contain (1,"Super Tablet - 1",1) (2, "Super Tablet - 2", 1) (3, "punyTablet", 2)
specs would contain (1,1,"500gb hd") (2,1, "750gb hd") (3, 2, "500gb hd") (4,3, "100gb hd")




If he was at the level where an additional cache count table was necessary he wouldn't be asking for help here.
If you use a properly designed schema like mine, querying those things is trivial.


You would need another table, maybe called computers that used your above tables.

i.e.

table computers
id, type (ref computer-types), category (ref computer-categories), model (ref computer-models), specs (ref computer-specs)

so it would look something like (1, 1, 2, 2)

This post was edited by DirtyRasa on Sep 12 2013 07:08am
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Sep 12 2013 07:58am
Thanks for all of the feedback guys.
I'm going to go with the agreed upon method of using a separate table for each "level" such has
Table: Computers
Table: ComputerType
Table: ComputerCategories
Table: ComputerModels
etc. etc.

Which was my plan all along, but I wasn't sure how many tables/which tables I needed to keep my database well normalized.
However, starting a fresh day and reading all this wonderful feedback has, I believe, helped me get my head around things.

Seriously guys/gals, the feed back is super appreciated.
I wear a dozen different hats at work, and I often find my self multitasking between web development, computer repairs, customer service, dba, manual labor, so on and so forth
It can be very challenging going from DBA, to a crucial computer repair, then a customer calls, then I go back to the repair task, then I get to go back to DBA and try and remember where I left off..
I take good notes and comment well, but you here at D2JSP's Programmer Haven are invaluable! :love:

This post was edited by grievance on Sep 12 2013 07:58am
Member
Posts: 2,045
Joined: Oct 7 2009
Gold: 0.21
Sep 15 2013 05:22pm
honestly, i would suggest the fbdevelopers group, they allow off topic threads if they are going to be socially active in any way, I get great results as long as the question is fluent with the purpose & information.. other than that maybe w3schools can shed some light on you're tricky situation.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll