Composite Keys & References

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OuTCasT
    Contributor
    • Jan 2008
    • 374

    Composite Keys & References

    I have 2 tables, eg. EarningDescript ions and EmployeeDetails with 1 column in each to simplify the question. EarningsLineNo in EarningsDescrip tions 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 :

    Code:
     
    Create table Earnings
    (
    EarningLineNo int references EarningDescriptions(EarningLineNo) not null,
    EmployeeCode nvarchar(50) references EmployeeDetails(EmployeeCode) not null,
    EarningAmount decimal not null,
    Primary key (EarningLineNo, EmployeeCode)
    )
    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....
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    that is used to maintain referential integrity.

    Comment

    Working...