Home | Submit an interview question | Filter by category | Filter by job function | Filter by company
 
Member Information
User Id
Password
 
Forgot Password
Technology Category
.NET (1202)
Languages (103)
Database (146)
Operating System (48)
Reporting (5)
Third-Party Tools (2)
Testing (91)
OOP (75)
Web Development (40)
Design Patterns (89)
General (9)
Networking (88)
Hardware (63)
Brain Exercise (2)
Others (37)
 Our Network
.NET Heaven
C# Corner
Interview Corner
Longhorn Corner
Mindcracker
VB.NET Heaven
Home » Database » Database
What is difference between UNIQUE and PRIMARY KEY constraints
Posted by Puran Mehra Aug 04, 2006
Viewed : 21794 times
Major Category : Database
Minor Category : SQL Server
Total Replies : 8
Become a Sponsor
 EDITORIAL ANSWER  
No Reply Yet
 ANSWERS BY USERS  
asma farrukh
Aug 22, 2009

A table must contain only one primary key.if a table contains more than one primary key,then these are called composite keys.a primary key must be unique.but a unique key can't be a primary key.a table contains more than one unidue keys but a table must be identified by it's primary key. 

pula narasima
Jan 05, 2009

Primary key:
1)Primary key is nothing but it is uniqly identified each roe in Table.
2)Primary key Does not Allowes Duplicate values and Null values.
3)Primary key is default Clustered indexes
4)One table can have only one Primary key.
Unique Key:
1)Unique Key is nothing but it is uniqly identified each roe in Table.
2)Unique Key Does not Allowes Duplicate values but allowes only one Null value.
3)Primary key is default Non- Clustered indexes

Regards,

Narasima

sanjeev singh
Aug 22, 2008
The basic differences between Primary Key and Unique key are as follows. 1) By default Primary Key will generate Clustured Index whereas Unique Key will Generate Non-Clustured Index. 2) Primary Key is a combination of Unique and NOT NULL Constraints so it can’t have duplicate values or any NUll Whereas for Oracle UNIQUE Key can have any number of NULL whereas for SQL Server It can have only one NULL 3) A table can have only one PK but It can have any number of UNIQUE Key.
manohar reddy
Jun 10, 2008
  • PRIMARY KEY: A tabLe can aontain only one PRIMARY KEY. It Doesn't allow null values, it is used  as Foreign Key In Another Table(like Reference Key).

 

  • UNIQUE: A Table may Contain  one or more UNIQUE  constraints. Its aloow only one null value . Use this key We maintain unique vales in the table.
Mohd Nasar
Mar 12, 2008
Both PRIMARY KEY constraint and UNIQUE constraint uses to enforce Entity integrity (defines a row as a unique entity for a particular table), but primary keys do not allow null values.
madhukumar koppula
Aug 17, 2006

Both Primary and Unique Keys are enforce uniqueness of the column. But the differeces are given below:

Primary Key:

1) It creates clustered index by default

2) It doesn't allow nulls

Unique Key:

1) It creates non-clustered index by default

2) It allows only one null value

 

Regards

MadhuKumarKoppula


Aug 04, 2006

PRIMARY KEY Constraint

Specifies the column that uniquely identifies a row in the table. The identified columns must be defined as NOT NULL.

Note: If you attempt to add a primary key using ALTER TABLE and any of the columns included in the primary key contain null values, an error will be generated and the primary key will not be added. See ALTER TABLE statement for more information.

UNIQUE KEY Constraint

Specifies that values in the column must be unique. NULL values are not allowed.

Thanks!
Manoj [InfoAxon Technologies Ltd.]

Puran Mehra
Aug 04, 2006

A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys.

The columns that compose PK are automatically define NOT NULL, whereas a column that compose a UNIQUE is not automatically defined to be mandatory must also specify the column is NOT NULL.

  
1

 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Advertise with us
Current Version: 2.2009.3.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved