Pages

May 27, 2011

Interview Questions: What is the difference between unique-key and primary-key in database (Oracle , Microsoft SQL Server, Access , MySQL etc)

Interview Questions: What is the difference between unique-key and primary-key in database (Oracle , Microsoft SQL Server, Access , MySQL etc...)

This is a mature question , I myself had faced this question in an interview but couldn't describe all the points but I was able to describe the main key point of this question "What is the difference between unique-key and primary-key in database".


The main key points of this question( "What is the difference between unique-key and primary-key in database") is below number 1,2.


1) Unique key (UK) can be null but Primary key can't be null.
2) Primary key (PK) can be referenced to other Data-tables as a Foreign(FK) but 

Unique key (UK) can't play this role.

3) We can have multiple unique keys(UK) in a table but in the case of Primary key (PK) there should be only one.
4) And also a primary key creates a cluster-index by default but unique key creates a non-cluster-index by default.


More Explanation: 
Primary Key is a combination of Unique and NOT NULL Constraints so it can’t have duplicate values or any null values.
Moreover in Oracle Databases,  UNIQUE Key Columns can have any number of NULL values, however in MS SQL Server/ Microsoft-Access can only have one NULL value in  their unique key column.

What is Foreign Key:

Related links in What is the difference between unique-key and primary-key:

SEO Labels:

Uniquekey and primarykey Difference

What is the difference between unique-key and primary-key

Interview Questions: What is the difference between unique-key and primary-key , 

Foreign ,Key, Primary ,Key, Unique, Key

No comments:

Post a Comment