GeekInterview.com
Series: Subject: Topic:
Question: 398 of 492

what is difference between "Primary key" and "Unique key"?

Asked by: Interview Candidate | Asked on: Mar 18th, 2006
Showing Answers 1 - 29 of 29 Answers
Culver_lake

Answered On : Mar 18th, 2006

View all answers by Culver_lake

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.

  
Login to rate this answer.
prema

Answered On : Mar 20th, 2006

Primary key and unique are Entity integrity constraintsPrimary 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).

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

Answered On : Mar 24th, 2006

Primary key can't be null but unique key can be null.

  
Login to rate this answer.
Culver_lake

Answered On : Mar 24th, 2006

View all answers by Culver_lake

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.

  
Login to rate this answer.
pramod kumar

Answered On : Apr 6th, 2006

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

  
Login to rate this answer.
pramod kumar

Answered On : Apr 6th, 2006

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

  
Login to rate this answer.
pramod kumar

Answered On : Apr 6th, 2006

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.

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

Answered On : Apr 6th, 2006

UNIQUE KEY accepts null value whereas primary key does not accept null value anda table can have more then one unique key column ,but a table can have only one primary key columnprimary key creates clustered index ,but unique key creates non clustered index.

  
Login to rate this answer.
dhk

Answered On : Apr 20th, 2006

View all answers by dhk

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          

  
Login to rate this answer.
Giridhar Ks

Answered On : May 7th, 2006

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.

  
Login to rate this answer.
Vinay Kumar

Answered On : May 29th, 2007

one more difference is:- Primary key creates the Clustered index, but unique key creates the Non clustered index.

  
Login to rate this answer.
Ajitabh Kumar

Answered On : Jun 8th, 2007

Primary key accepts only non duplicate value and not accept null value and only one primary key may have in tableUnique key can have more than one null value , there may be more than one unique key in a table

  
Login to rate this answer.

Primary key: -                      1) Can only one in a table                     2) We can't insert duplicate value or same value                     3) Can use as a foreighen key for other table                     4) It never allow Null values.Unique key: -                      1) There can be more than one unique key in one table                     2) Unique key can have Null Values                     3) It can't be a candidate key

  
Login to rate this answer.

Primary key is unique key identifier  and cannot be null and can be unique unique key  can be null and cannot be unique 

  
Login to rate this answer.
jamestjacob

Answered On : Jun 6th, 2008

View all answers by jamestjacob

Waiting for the correct answer

  
Login to rate this answer.
sravee123

Answered On : Jun 9th, 2008

View all answers by sravee123

Primary can't be null but unique key allows one null value..&PRIMARY KEY:In a table we can create only one primarykey UNIQUE KEY: we can create no. of unique keys in a table..

  
Login to rate this answer.
satinder_simmi

Answered On : Jun 20th, 2008

View all answers by satinder_simmi

The main differance is that unique key may be not null constraint or not may be.but in primary key not null constraint is defined defaultly

  
Login to rate this answer.

The main differences between a primary key and a unique key is that a primary key (although unique) cannot contain NULL values, whereas a Unique Key can.

  
Login to rate this answer.
shakilag

Answered On : Jun 30th, 2009

View all answers by shakilag

Following are the differences between Primary and Unique constraints:1) The columns that are primary keys cannot contain NULL values as primary key is meant to uniquely identify a record in a table. The columns that make a unique key can be nullable as unique key just restricts a column not to hold duplicates . 2) There can be only one primary key per table while there can be N number of unique keys defined in a table.3) By default a clustered index is created on a primary key while a non clustered index is created on a unique key.

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

Answered On : Jul 1st, 2009

View all answers by dj_dj_dj

Primary Key is Key which don't allows any duplicate values or null values to be inserted. Whereas, Unique key also don't allows duplicate values to be inserted but it allows null values to be inserted because null values cannot be compared to anything.

Regards
Dharmendra Jaiswal
CMS.

  
Login to rate this answer.
easwarancs

Answered On : Oct 26th, 2009

View all answers by easwarancs

A Unique Key can have null values but a Primary Key can't have null values

  
Login to rate this answer.

The Unique key contains only one null value. The Primary key has not allow the null value.

  
Login to rate this answer.
b.ganeshna

Answered On : Feb 17th, 2010

View all answers by b.ganeshna

The main difference of primary key and the unique key is:Primary key does not allow null values as well as duplicate values.But incase of unique key it does not allow duplicate values but it allows null values.

  
Login to rate this answer.
girlgeek1

Answered On : Mar 2nd, 2010

View all answers by girlgeek1

A primary key is both unique and not null.  There can only be one primary key per row.  It is what defines the row.  The primary key is the 'name' of the row.

  
Login to rate this answer.
sktest

Answered On : Jul 11th, 2010

View all answers by sktest

Primary key is used to identify row which is unique and not nullUnique key is used to identify distinct row, it can contian null value

  
Login to rate this answer.
machomanic

Answered On : Jul 12th, 2010

View all answers by machomanic

Primay Key: Unique field in the table which cannot be duplicated and cannot be NULL.Unique Key: Uniqueu field in the table but can be NULL

  
Login to rate this answer.
ajayraj

Answered On : Dec 30th, 2010

View all answers by ajayraj

The Difference between Primary Key and Unique is as follows :1. Primary Key does not allow null value but Unique key allow.2. In a Table There will be only one primary key but Unique key cam be more than  one.3. In case of creating a master - detail relation between two tables If You are referencing Primary key in another table then no need to specify column name but in case of unique you must have to specify column name.4. Primary Key creates clustered index where as unique creates non clustered index.Example for Primary Key:- CREATE TABLE aa (a1 NUMBER(5) PRIMARY KEY,b1 VARCHAR2 (20));CREATE TABLE bb (a2 NUMBER(5),b2 VARCHAR2 (20), FOREIGN KEY(a2) REFERENCES aa);Example for Unique Key :-CREATE TABLE cc (a3 NUMBER(5) UNIQUE,b1 VARCHAR2 (20));CREATE TABLE dd (a4 NUMBER(5),b4 VARCHAR2 (20), FOREIGN KEY(a4) REFERENCES cc(a3));

  
Login to rate this answer.

Both primary key and unique contain unique value.1: primary key cant be nullUnique key can be null.2: Multiple column of table van be defined as unique key.Only one column can defined as primary key

  
Login to rate this answer.

Primary KEY is the combination of UNIQUE and NOT NULL constraint

  
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.