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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Primary key
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic
Starting Member

19 Posts

Posted - 12/02/2013 :  13:15:20  Show Profile  Reply with Quote
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??

Almighty SQL Goddess

38200 Posts

Posted - 12/02/2013 :  13:56:19  Show Profile  Visit tkizer's Homepage  Reply with Quote
Just add a unique index/constraint if you need to define more than one.

Tara Kizer
SQL Server MVP since 2007
Go to Top of Page
Starting Member

19 Posts

Posted - 12/02/2013 :  21:23:30  Show Profile  Reply with Quote
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??

Edited by - on 12/03/2013 00:27:29
Go to Top of Page

Flowing Fount of Yak Knowledge

4614 Posts

Posted - 12/03/2013 :  12:11:41  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000