SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

gautham.gn
Starting Member

India
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??

tkizer
Almighty SQL Goddess

USA
37316 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
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

gautham.gn
Starting Member

India
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 - gautham.gn on 12/03/2013 00:27:29
Go to Top of Page

Lamprey
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  
 New 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.05 seconds. Powered By: Snitz Forums 2000