467,915 Members | 1,204 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

Composite Keys & References

OuTCasT
256MB
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
  • viewed: 1067
Share:
1 Reply
debasisdas
Expert 4TB
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.

Similar topics

3 posts views Thread by Girish Agarwal | last post: by
18 posts views Thread by Thomas A. Anderson | last post: by
4 posts views Thread by Ismail Rajput | last post: by
7 posts views Thread by Ronald S. Cook | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.