Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is the difference between primary key and unique key not null?

this question related to database

user-image
Question added by Inamullah Buksh , web development , vision solution
Date Posted: 2014/03/03
Rashid Anwar
by Rashid Anwar , senior php developer , sparx it solution pvt ltd.

Primary Key: A primary key is a single column or combination of columns that uniquely identifies a record. None of the columns that are part of the primary key can contain a null value.A table can have multiple unique and foreign keys. However, a table can have only one primary key.

Unique Key: A unique key or primary key [is a candidate key] to uniquely identify each row in a table. It can be comprised of either a single column or multiple columns. The major difference is that for unique keys the implicit NOT NULL constraint is not automatically enforced, while for primary keys it is enforced. Thus, the values in unique key columns may or may not be NULL.

 

Differences between Primary Key and Unique Key

1. Primary Key does not accept null value whereas Unique Keys accepts null value.     

2. There will be only one primary key in a table whereas More than one unique key will be there in a table.       

3. Clustered index is created in Primary key whereas Non-Clustered index is created in unique key.       

4. Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist whereas unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values.

 

Muhammad Majid Saleem
by Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech
Inamullah Buksh
by Inamullah Buksh , web development , vision solution

yes right answer. primary key is not allow null value but unique key allow null value.

Anas M.A
by Anas M.A , SOFTWARE DEVELOPER , PEAK TECHNO LINKS PVT.LTD

Both are  used for Unique Identification of data.But the Main difference is primary key won't allow null values but unique key will  allow maximum one Null value.

mandal rushikesh
by mandal rushikesh , PHP Developer , Fedobe Solutions Pvt Ltd

In a table there can be only one primary key but you can have multiple unique keys not null

 

Abdul Saboor Rana
by Abdul Saboor Rana , Senior Software Engineer , trg

Primary Key: Only one/table ,unique,not null

Unique Key: can be many/table,allows null

Every primary is a unique but every unique is not primary

 

primary key=unique +not null.

unique key +not null=candidate key,

candidate keys are the nominies of primary key

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.