Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Primary Key/Composite Key

Author  Topic 

john.lam
Starting Member

12 Posts

Posted - 2009-07-22 : 13:41:19
Hi all,

If I have 6 columns in a table: RecordId, LocationId, Year, ActivityId, Nature and ProgramId, the combination of them represents a unique record in the table but the data in the individual columns may not be unique, in SQL Server 2005, should I assign Primary Key to each of these 6 columns as Composite Key or there is a better approach to it?

Thanks!

John Lam

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-22 : 13:44:10
Depending on how you use (and query) the data, you may want to assign a surrogate PK. This menas adding an identity column and make that the PK. You will still want to enforce uniqueness over your natural key though.

One advantage of the identity field is that it is much easier to handle in application code, where you are passing around one integer value rather than 6 values.
Go to Top of Page
   

- Advertisement -