GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 25 of 166    Print  
what is difference between "Primary key" and "Unique key"?

  
Total Answers and Comments: 21 Last Update: October 26, 2009     Asked by: Babar Shabbir 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: prema
 

Primary key and unique are Entity integrity constraints

Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist and no null values are entered.

Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values. (In oracle, one null is not equal to another null).



Above answer was rated as good by the following members:
aravindmca08
  Sorting Options  
  Page 1 of 3   « First    1    2    3    >     Last »  
March 18, 2006 22:11:43   #1  
Culver_lake Member Since: March 2006   Contribution: 46    

RE: what is difference between "Primary key" and "Uniq...
A unique key has the property that no two values in the range are the same. A primary key is chosen from among all the unique keys of a table to participate in referential integrity constraints. Primary keys are unique by definition.
 
Is this answer useful? Yes | No
March 20, 2006 03:13:43   #2  
prema        

RE: what is difference between "Primary key" and "Uniq...

Primary key and unique are Entity integrity constraints

Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist and no null values are entered.

Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values. (In oracle one null is not equal to another null).


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 24, 2006 01:34:39   #3  
Rana Irfan        

RE: what is difference between "Primary key" and "Uniq...
Primary key can't be null but unique key can be null.
 
Is this answer useful? Yes | No
March 24, 2006 08:47:31   #4  
Culver_lake Member Since: March 2006   Contribution: 46    

RE: what is difference between "Primary key" and "Uniq...

sorry rana unique constraints do not include null. Null is not a value it's a state where the value is unknown. In DB2 a unique constraint MUST include the NOT NULL clause.

Even if allowed the index used to guarantee uniqueness could at most have one entry for NULL. This would assume that NULL was treated as a value. DB2 has a special property for an index namely: UNIQUE WHERE NOT NULL which allows multiple instances of NULL but forces unique values. This is good for M:1 relations where the many side is optional in the relationship. DB2's index is a very special case. Don't go looking for it in other RDBMS products.


 
Is this answer useful? Yes | No
April 06, 2006 04:02:54   #5  
pramod kumar        

RE: what is difference between "Primary key" and "Uniq...

1)unique key can be null but primariy key cant be null.

2)primariy key can be refrenced to other table as FK.

3)we


 
Is this answer useful? Yes | No
April 06, 2006 04:02:55   #6  
pramod kumar        

RE: what is difference between "Primary key" and "Uniq...

1)unique key can be null but primariy key cant be null.

2)primariy key can be refrenced to other table as FK.

3)we can have


 
Is this answer useful? Yes | No
April 06, 2006 04:04:30   #7  
pramod kumar        

RE: what is difference between "Primary key" and "Uniq...

1)unique key can be null but primariy key cant be null.

2)primariy key can be refrenced to other table as FK.

3)we can have multiple unique key in a table but PK is one and only one.

4)PK in itself is unique key.


 
Is this answer useful? Yes | No
April 06, 2006 09:10:41   #8  
Karthikeyan        

RE: what is difference between "Primary key" and "Uniq...

UNIQUE KEY accepts null value whereas primary key does not accept null value and

a table can have more then one unique key column but a table can have only one primary key column

primary key creates clustered index but unique key creates non clustered index.


 
Is this answer useful? Yes | No
April 20, 2006 15:50:13   #9  
dhk Member Since: April 2006   Contribution: 3    

RE: what is difference between "Primary key" and "Uniq...

Primary which allows only unique+not null values

where has unique allow unique and null values because a null value is not equal to a null value


 
Is this answer useful? Yes | No
May 07, 2006 10:59:38   #10  
Giridhar Ks        

RE: what is difference between "Primary key" and "Uniq...

Primary Key:- Primary Key is an attribute or a set of attributes in a table which uniquely identifies a record (row) in a table and no two records (rows) in the table can have the same values for all the columns comprising the primary key.

Unique Key:- A unique key is a key which stores unique values (no duplicates) for that particular column.

Difference between Primary Key & Unique Key:-

1. A Unique key can store a null value and primary key cannot store any null value.

2. A primary key can be references to another table as a Foreign Key.


 
Is this answer useful? Yes | No
  Page 1 of 3   « First    1    2    3    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape