Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 11:48
lmei007 lmei007 is offline
Registered User
 
Join Date: Jun 2008
Posts: 18
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, 12:33
georgev georgev is offline
SQL Apprentice
 
Join Date: Jan 2007
Location: hiding
Posts: 8,131
You're asking the right questions, but your asking the wrong people - we don't know what your business requirements are.
__________________
George
You only stop learning when you stop asking questions.
Reply With Quote
  #3 (permalink)  
Old 06-05-08, 13:15
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 9,274
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
http://sqlblindman.googlepages.com/main
Reply With Quote
  #4 (permalink)  
Old 06-05-08, 13:28
mike_bike_kite mike_bike_kite is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 944
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

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