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 > referential integrity?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-09-08, 18:37
lmei007 lmei007 is offline
Registered User
 
Join Date: Jun 2008
Posts: 18
referential integrity?

I have COMPANY, BANK, CUSTOMER tables which contain state, city columns. I have two options right now for the state and city column.

Option 1: just put value in those tables;

Option 2: create a CITY and STATE table to hold value for city and state and have COMPANY, BANK, CUSTOMER tables a reference to CITY and STATE table to get the value. For example the STATE table may has two columns: stateName and countryCode, the CITY table may has two columns: cityName and stateName. In BANK, COMPANY, CUSTOMER tables, the stateName and cityName will be there and they will be a foreign key to CITY and STATE table.

sounds option 2 is better but it will create unnecessary join and downgrade the performance?

thanks
Reply With Quote
  #2 (permalink)  
Old 06-09-08, 19:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,539
"better" based on what criteria?

i kind of like option 1 because you have given no evidence that there is a need for option 2

here's an interesting comparison --

suppose you had a table of employees, and each employee has a firstname and a lastname

would you create a firstname table and link all the firstnames to it via relational integrity? would you create a lastname table and link all the lastnames to it via relational integrity? if not, why not?

what makes the firstname/lastname relational integrity question any different from cities and states?
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 06-09-08, 21:23
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 9,274
If you are going to store additional information about each city and/or State, such as demographics, or date of last survey, or whatever, then these represent distinct informational entities and should be split out into separate tables.
If you want to ensure consistent spelling of city or State names across the database, to prevent people from entering "Minnesota" and "Minesota", or both "St Paul" and "St. Paul", or you want to prevent people from entering "Indianapolis, Nebraska", then you need to split these out into separate tables to ensure data integrity.
Otherwise, leave them as attributes of the Custom, Bank, or Company.
__________________
If it's not practically useful, then it's practically useless.

blindman
http://sqlblindman.googlepages.com/main
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