By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,659 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,659 IT Pros & Developers. It's quick & easy.

Composite Keys & References

OuTCasT
100+
P: 374
I have 2 tables, eg. EarningDescriptions and EmployeeDetails with 1 column in each to simplify the question. EarningsLineNo in EarningsDescriptions and EmployeeCode in EmployeeDetails.

i created another table that references 2 columns in that table to the 2 columns in the other 2 tables as such :

Expand|Select|Wrap|Line Numbers
  1.  
  2. Create table Earnings
  3. (
  4. EarningLineNo int references EarningDescriptions(EarningLineNo) not null,
  5. EmployeeCode nvarchar(50) references EmployeeDetails(EmployeeCode) not null,
  6. EarningAmount decimal not null,
  7. Primary key (EarningLineNo, EmployeeCode)
  8. )
  9.  
I used a composite key because the EarningLineNo and EmployeeCode in the new table will be used over and over again. but the same combination wld not be for instance. 1-1. 2-3 etc

I would like to knw what the referencing to the other columns is actually for and if its necessary or not ?
Is it for saving purposes or maybe making sure information is similar in the columns in both tables....
Jan 22 '09 #1
Share this Question
Share on Google+
1 Reply


debasisdas
Expert 5K+
P: 8,127
that is used to maintain referential integrity.
Jan 22 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.