GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 7 of 169    Print  
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.



  
Total Answers and Comments: 11 Last Update: September 16, 2008   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Vijay Raj Jaiswal
 

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



Above answer was rated as good by the following members:
satyam_Ora, sbukka, spohilko, sumanpani
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
September 20, 2005 09:43:01   #1  
Vijay Raj Jaiswal        

RE: What is difference between UNIQUE and PRIMARY KEY ...

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


 
Is this answer useful? Yes | NoAnswer is useful 4   Answer is not useful 0Overall Rating: +4    
September 28, 2005 06:09:45   #2  
kalai        

RE: What is difference between UNIQUE and PRIMARY KEY ...
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.
 
Is this answer useful? Yes | NoAnswer is useful 3   Answer is not useful 0Overall Rating: +3    
October 23, 2006 10:23:26   #3  
sugapriyaraja        

RE: What is difference between UNIQUE and PRIMARY KEY ...

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

Unique Key: More then one column in a table, null values accepted


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 1Overall Rating: +1    
March 01, 2007 01:23:47   #4  
bala        

RE: What is difference between UNIQUE and PRIMARY KEY ...

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 one Null Value
Null value


 
Is this answer useful? Yes | No
May 23, 2007 07:54:26   #5  
amit        

RE: What is difference between UNIQUE and PRIMARY KEY ...
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.
 
Is this answer useful? Yes | No
July 06, 2007 05:20:48   #6  
Faizal        

RE: What is difference between UNIQUE and PRIMARY KEY ...
/*
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.


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
August 07, 2007 04:50:14   #7  
velsowmya Member Since: August 2007   Contribution: 7    

RE: What is difference between UNIQUE and PRIMARY KEY ...
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.

 
Is this answer useful? Yes | No
October 19, 2007 03:18:50   #8  
Rahul Kataria        

RE: What is difference between UNIQUE and PRIMARY KEY ...
Primary key cannot take null values but Unique can take null values

simply we can say

primary key = unique + not null

 
Is this answer useful? Yes | No
January 29, 2008 08:23:38   #9  
patilpravin_1981 Member Since: December 2007   Contribution: 29    

RE: What is difference between UNIQUE and PRIMARY KEY constraints?
unique key can contains one null value
primery key can not contain null value

 
Is this answer useful? Yes | No
May 29, 2008 08:00:14   #10  
ssusmitaa Member Since: March 2007   Contribution: 2    

RE: What is difference between UNIQUE and PRIMARY KEY constraints?
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 key
columns 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.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape