primary and unique CONSTRAINT [Resolved]

Posted by Senthilns2005 under Sql Server on 6/10/2011 | Points: 10 | Views : 2328 | Status : [Member] | Replies : 6
What is the difference between UNIQUE CONSTRAINT and
PRIMARY CONSTRAINT?

Regards
N.Senthilkumar



Responses

Posted by: PandianS on: 6/10/2011 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Primary Key:
1. Combination of NOT NULL and UNIQUE, So, It will not allow Duplicate data and NULL.
2. It will be CLUSTERED Index by default, If the table doesn't have CLUSTERED Index already on that table. It will be NONCLUSTERED PRIMARY KEY, If the table already have CLUSTERED Index on that table.
3. Only one PRIMARY KEY can be defined on the table.

UNIQUE:
1. It allows only one NULL
2. It will create NONCLUSTERED Index, Even the table doesn''t have CLUSTERED Index already on that table.
3. Multiple UNIQUE can be defined on the table.

Note:
PRIMARY KEY or UNIQUE constraint can be referenced by a FOREIGN KEY constraint.

Cheers
www.sqlserverbuddy.blogspot.com

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Senthilns2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Questpond on: 6/11/2011 [PanelMember] [Member] [Microsoft_MVP] [MVP] [Administrator] Starter | Points: 25

Up
0
Down
The below video should help you. It explain primary and unique constraints practically.
http://youtu.be/8iIvyNPwruU?hd=1

Senthilns2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gsolvers on: 6/11/2011 [Member] Starter | Points: 25

Up
0
Down
Great Answer PandianS!

Best Regards,

VG
www.TeacherJi.com

Senthilns2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 6/13/2011 [Member] Starter | Points: 25

Up
0
Down
unique is used to restrict duplicate values but it allows null values so restrict null values we are using not null but it allows duplicate values.
to restrict duplicate values and null values we are using primary key constraint.

Thanks&Regards
LakshmiNarayana Nalluri.

Senthilns2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 11/24/2011 [Member] Starter | Points: 25

Up
0
Down
Primary Key:

Primary Key Restrice Duplicate Values and Null values.Each Table Can have only one primary key.By Default Clustered index is an Primary Key.

Unique Key:

Unique key Restrict Duplicate Values and Allow only one Null values. by Default non Clustered Index is an Unique Key.

Regards
Sriram.R

sriram

Senthilns2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajeev.Shukla on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
Primary Key:
Prmary Key is the unique identifier of the table. Only Single Primary Key is possible on a table. Primary Key may the single column or combination of the columns. Null values not allowed in Primary Key. By default Clustered Index is created when you define a primary Key on a table.

Unique Key:
Only one NULL values is allowed in Unique key column. It is only on single column.


Senthilns2005, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response