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 > reference relationship between tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-05-08, 10:48
lmei007 lmei007 is offline
Registered User
 
Join Date: Jun 2008
Posts: 20
reference relationship between tables

Have a question on how to connect tables. if I have a CUSTOMER table (with custid as primary key) and a BANK_ACCOUNT table (with accountid as primary key). To connect them together, we have at least two options:

option 1:
put accountid into CUSTOMER table as a foreign key

option 2:
put custid into BANK_ACCOUNT table as a foreign key

to me option 2 may be better because it can handle one customer has more than one account case. But how about if that account is a shared account which shared by a hushand and wife, and the husband and wife are separated customer in this system? Then we need another table in between to resolve this?

What's your opinon? do we have general rules for those cases?
Reply With Quote
  #2 (permalink)  
Old 06-05-08, 11:33
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
You're asking the right questions, but your asking the wrong people - we don't know what your business requirements are.
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 06-05-08, 12:15
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
When an account can be shared, you need to implement a many-to-many relationship. This is done by creating a third table that contains AccountID and CustomerID as a unique composite key.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #4 (permalink)  
Old 06-05-08, 12:28
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Just have a separate CUSTOMER_BANK_ACCOUNT table surely.

Code:
CUSTOMER_BANK_ACCOUNT : custid, accountid, role
With role to show who's the primary owner of the account. This handles 1:M, M:1 or M:M between customers and accounts.

Edit : Sorry blindman - didn't see your reply until too late.
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