GeekInterview.com
Series: Subject: Topic:
Question: 423 of 429

What is difference between UNIQUE and PRIMARY KEY constraints?

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.
Asked by: Interview Candidate | Asked on: Aug 29th, 2004

Editorial / Best Answer

Answered by: Vijay Raj Jaiswal

Answered On : Sep 20th, 2005

Hi this is modified answer ,pls post this instead of previous which i post

Primay Key                     Unique key

-----------                  ------------------

There is only one         there may be more than 1
Primary key for           Unique Key in table
1 table

It can not contain           It Can contain Null Value
Null value

Showing Answers 1 - 12 of 12 Answers
Vijay Raj Jaiswal

Answered On : Sep 20th, 2005

Hi this is modified answer ,pls post this instead of previous which i postPrimay Key                     Unique key-----------                  ------------------There is only one         there may be more than 1Primary key for           Unique Key in table 1 tableIt can not contain           It Can contain Null ValueNull value

Yes  6 Users have rated as useful.
  
Login to rate this answer.
kalai

Answered On : Sep 28th, 2005

Primary key creates clustered index whereas unique key creates non clustered index.primary key won't allow NULL values whereas unique key allows NULL values.

Yes  3 Users have rated as useful.
  
Login to rate this answer.
sugapriyaraja

Answered On : Oct 23rd, 2006

Primary Key: only one column in a table,not accepted null values.Unique Key: More then one column in a table, null values accepted. 

Yes  2 Users have rated as useful.
  
Login to rate this answer.
bala

Answered On : Mar 1st, 2007

Primay Key                     Unique key-----------                  ------------------There is only one         there may be more than 1Primary key for           Unique Key in table 1 tableIt can not contain           It Can contain one Null ValueNull value

  
Login to rate this answer.
amit

Answered On : May 23rd, 2007

Primary key creates clustered index whereas unique key creates non clustered index. Primary key won't allow NULL values whereas unique key allows only one NULL values.

  
Login to rate this answer.
Faizal

Answered On : Jul 6th, 2007

/*Just adding to the Primary Key Explanation*/Its right that there can be only one Primary Key for a Table.But for that Primary Key we can add more than one fields.Ex:ALTER TABLE emp ADD CONSTRAINT PRIMARY KEY(emp_no, dept_no, phone);By the above, all the 3 fields make a combination of a Primary Key.

  
Login to rate this answer.
velsowmya

Answered On : Aug 7th, 2007

View all answers by velsowmya

Primary key wont accept null values and a table can have only one primary key for a column.Unique key accepts null values.A table can have any number of unique keys.

  
Login to rate this answer.
Rahul Kataria

Answered On : Oct 19th, 2007

Primary key cannot take null values but Unique can take null valuessimply we can sayprimary key = unique + not null

  
Login to rate this answer.

Unique key can contains one null valueprimery key can not contain null value

  
Login to rate this answer.
ssusmitaa

Answered On : May 29th, 2008

View all answers by ssusmitaa

A table can have only one PRIMARY KEY where as can have numerous UNIQUE KEY . A PRIMARY KEY is a unique KEY with the extra constraint that all keycolumns must be defined as NOT NULL. But unique key column can contain null value only once. If UNIQUE KEY is defined on more than one column then null values can be in the table by unique combination of those columns. Another difference is that PRIMARY KEY constraints enforces clustered indexing where as UNIQUE KEY constrains are nonclustered indexes.

Yes  1 User has rated as useful.
  
Login to rate this answer.
sumanpani

Answered On : Sep 16th, 2008

View all answers by sumanpani

Primay Key                     Unique key-----------                  ------------------There is only one         there may be more than 1Primary key for           Unique Key in table 1 tableIt can not contain           It Can contain Null ValueNull valuePrimary key                      unique key creates non clustered indexcreates clustered index

  
Login to rate this answer.

Unique key means we have to enter unique value but we can enter null.But in case of Primary key we should have to enter Unique + Not Null value in that particular column.

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.