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
 New to SQL Server Programming
 Primary key

Author  Topic 

gautham.gn
Starting Member

19 Posts

Posted - 2013-12-02 : 13:15:20
There is a restriction that we must have only one primary key per table. We can have composite primary key by defining primary key over 2 or more columns. Actually,, a primary key uniquely defines the table and if we have two or more columns which follow unique and not null features why can't we have two primary keys?? I want to know what is the main reason behind having only one primary key in a table??

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-12-02 : 13:56:19
Just add a unique index/constraint if you need to define more than one.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

gautham.gn
Starting Member

19 Posts

Posted - 2013-12-02 : 21:23:30
I know that I can add one more unique constraint on a column but I want the reason why there is a restriction that a table should have only one primary key?? Why not 2 or more??
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-12-03 : 12:11:41
SQL Server only allows one primary key. It's like having two children and saying they are both first born; It doesn't make sense. In reality a PK is only a unique constraint on a non-nullable column, but it has the special distinction on being "primary." Additionally, people tend to associate the clustering of a table on the primary key, although that is not a requirement for a PK.
Go to Top of Page
   

- Advertisement -