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 > entity with multiple relations?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-26-04, 14:59
Tomat Tomat is offline
Registered User
 
Join Date: Jun 2004
Posts: 2
entity with multiple relations?

hey, I guess this will be my first message on your fine forum.

I have 3 entities of interest, and I am wondering how to form the relationships.

I have a 'shop' entity, a 'user', and an 'item'. Items are related to shop, until purchased, then they are related to user.

My question is, how do I form the relationship? I thought I could do it in two ways;

1) have multiple foreign keys in item, so maybe itemid, shopid, userid, and only use one of shopid userid at once.

2) use some kind of link table with itemid, and 'parententityname' or something

I'm lost...

can anyone help?




thankyou !

Tom
Reply With Quote
  #2 (permalink)  
Old 06-26-04, 21:55
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
If an item can only belong to one shop then the shop entity need not be related to item.

User is a many to many relationship with Item.

Your schema will therefore be:

Shop(shop_id, details)
Item(item_id, details)
User(user_id, details)
UserPurchases(user_id, item_id, qty, date)
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
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