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
 Combined Primary Keys possible?

Author  Topic 

monfu
Yak Posting Veteran

81 Posts

Posted - 2008-11-05 : 05:51:59
Dear All

I have a table Pages and it has the following fields

PageId smallint
PageName nvarchar(250)
PageTitle nvarchar(250)
fk_buildId int

Now normally, how I do it, set the PageId as int and make it the primary key with autoincrement.

However, someone suggested to me to put a combined primary key of PageId and fk_BuildId and set the PageId to smallint, and reset to zero whenever the fk_buildId changes. This is done to avoid the PageId being an int.

What is the normal standard of doing this? 1 PK with autoincrement or a combination of 2 PK's? I am asking since to keep a comb of 2 PK's requires more work and inserts a little bit of more complexity to it.

Thanks for your help and time

Johann

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-05 : 07:42:14
quote:
Originally posted by monfu

Dear All

I have a table Pages and it has the following fields

PageId smallint
PageName nvarchar(250)
PageTitle nvarchar(250)
fk_buildId int

Now normally, how I do it, set the PageId as int and make it the primary key with autoincrement.
make it identity column and create primary key constraint on it
However, someone suggested to me to put a combined primary key of PageId and fk_BuildId and set the PageId to smallint, and reset to zero whenever the fk_buildId changes. This is done to avoid the PageId being an int.
didnt understand why you want to include fk into pk. can you explain?

What is the normal standard of doing this? 1 PK with autoincrement or a combination of 2 PK's? I am asking since to keep a comb of 2 PK's requires more work and inserts a little bit of more complexity to it.
i think former is a better approach unless you've any specific reason

Thanks for your help and time

Johann

Go to Top of Page

monfu
Yak Posting Veteran

81 Posts

Posted - 2008-11-05 : 08:44:16
basically I am talking about surrogate and natural keys
Go to Top of Page
   

- Advertisement -