If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > need suggestions for a simple inventory DB design

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-05-04, 17:33
mypatpat mypatpat is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
need suggestions for a simple inventory DB design

Hello guys, please criticize what I have here...

It's a simple inventory database with 4 tables:

catagory(id, name)

subcatagory(id, c_id, name), c_id references catagory(id)

supplier(id, name, address, ..... )

items(id, s_id, c_id, sc_id, name, price, ...), s_id references supplier(id), c_id references catagory(id), sc_id references subcatagory(id)

So, in my design, subcatagory and items are weak entities, as they are both not uniquely identifiable by only their primary key.

Any suggestions on this design? Should I keep my weak entities or eliminate them and add relationship tables instead?
Reply With Quote
  #2 (permalink)  
Old 09-06-04, 01:27
mypatpat mypatpat is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
Quote:
Originally Posted by mypatpat
subcatagory(id, c_id, name), c_id references catagory(id)
One more thing, is it alright to have a foreign key (c_id in this case) as one of the primary keys? Since the id itself doesn't uniquely identify the name of the subcatagory, but id,c_id -> name
Reply With Quote
  #3 (permalink)  
Old 09-06-04, 01:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
your design is fine

many people would put the subcategories into the same table along with the categories

also, the items should relate to the subcategory but not the category as well, so that you can "transfer" a subcategory from one category to a different category by manipulating the subcategory's foreign key to the category, and thereby not have to make any change to the items at all
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 09-06-04, 18:24
mypatpat mypatpat is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
Quote:
Originally Posted by r937
many people would put the subcategories into the same table along with the categories
Is this what you mean?

1 A A1
2 A A2
3 A A3
4 B B1
5 B B2
6 C C1
7 ......

Does this not generate redundant data?
Reply With Quote
  #5 (permalink)  
Old 09-06-04, 18:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
no, like this --

id name parentid
1 animal NULL
2 vegetable NULL
3 mineral NULL
4 doggie 1
5 kittie 1
6 horsie 1
7 gerbil 1
8 birdie 1
9 carrot 2
10 tomato 2
11 potato 2
12 celery 2
13 rutabaga 2
14 quartz 3
15 feldspar 3
16 silica 3
17 gypsum 3
18 hunting 4
19 companion 4
20 herding 4
21 setter 18
22 pointer 18
23 terrier 18
24 poodle 19
25 chihuahua 19
26 shepherd 20
27 collie 20

this is called the adjacency model

see? no redundancy, and unlimited levels of subcategories, if you need them
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 09-06-04, 19:14
mypatpat mypatpat is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
I see. I guess I over analyized the problem and forgot that it is natually a tree structure...

Thanks for your help
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On