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 > Table Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-04-09, 12:00
evant8950 evant8950 is offline
Registered User
 
Join Date: Aug 2009
Posts: 7
Table Question

I have the table Items which is a child of Platform. Each platform can have multiple items. I need to make a new table, which I will call WPE which can also have multiple items. What would be the best way to make this work. Should I make a new foreign key in Items?

Thanks
Reply With Quote
  #2 (permalink)  
Old 08-04-09, 12:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by evant8950
Should I make a new foreign key in Items?
if you want Items to be a child of WPE, then the answer is yes
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-04-09, 13:06
evant8950 evant8950 is offline
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks. So it is ok for items to be a child of platform and WPE? I was wondering if this is a situation where you needed to use a junction table.
Reply With Quote
  #4 (permalink)  
Old 08-04-09, 13:09
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by evant8950
Thanks. So it is ok for items to be a child of platform and WPE?
sure, in exactly the same way that it's okay for a product to be a child of a vendor at the same time as being a child of a product category

Quote:
Originally Posted by evant8950
I was wondering if this is a situation where you needed to use a junction table.
probably not

but note that if both of the FKs are declared as NOT NULL, then the items table is a junction table between platforms and WPEs
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 08-04-09, 13:17
evant8950 evant8950 is offline
Registered User
 
Join Date: Aug 2009
Posts: 7
Some items will not be a child of WPE, so it can be null. So items will not be a junction table. My items table looks like it would be a junction table.
Reply With Quote
  #6 (permalink)  
Old 08-04-09, 14:28
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
I would do it like this and without nulls:

WPE {WPEId} KEY {WPEId}
Item {ItemId, PlatformId} KEY {ItemId} (or {ItemId, PlatformId}??)
ItemWPE {ItemId, WPEId} KEY {ItemId} (or {ItemId, WPEId}??)

You don't need nulls to represent any kind of relationship.
Reply With Quote
  #7 (permalink)  
Old 08-04-09, 14:34
evant8950 evant8950 is offline
Registered User
 
Join Date: Aug 2009
Posts: 7
It would look something like this:

Platform - WPE
| |
Item-------

But each item may not be a child of WPE at all.

Last edited by evant8950; 08-04-09 at 14:38.
Reply With Quote
  #8 (permalink)  
Old 08-04-09, 14:35
evant8950 evant8950 is offline
Registered User
 
Join Date: Aug 2009
Posts: 7
That didn't come out correctly the second pipe is suppose to come down from WPE
Reply With Quote
  #9 (permalink)  
Old 08-04-09, 14:47
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
I think my suggestion is pretty close. You just need to decide whether the relationships are 1-many or many-many and choose your keys accordingly.
Reply With Quote
  #10 (permalink)  
Old 08-04-09, 14:49
evant8950 evant8950 is offline
Registered User
 
Join Date: Aug 2009
Posts: 7
If that particular item has no WPE then that foreign key is null. Correct?
Reply With Quote
  #11 (permalink)  
Old 08-04-09, 14:51
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Quote:
Originally Posted by evant8950
If that particular item has no WPE then that foreign key is null. Correct?
If an item has no WPE then it won't have a row in the ItemWPE table at all. No need for a row with a null in it.
Reply With Quote
  #12 (permalink)  
Old 08-04-09, 14:54
evant8950 evant8950 is offline
Registered User
 
Join Date: Aug 2009
Posts: 7
I see what you are doing. I thought of something similar. I just needed some direction on which route to take. Thanks!
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