Skip to main content
Announcements
Qlik Launches Open Lakehouse and advanced agentic AI experience in Qlik Answers! | LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
renjithpl
Specialist

Difference between a Primary key and Unique Key

Hi all,

Can any one explain me with examples whats the difference between a primary key and a unique key.

Thanks in advance

Ranjit

6 Replies
pover
Luminary Alumni

Ranjit,

From what I understand, a primery key is a unique key that has to be defined at the moment of creation for each row like EmployeeID in a table of Employees where the values are probably consecutive, and a unique key is a column that has unique values like Social Security Number and can be used to identify an employee, but is not required information at the moment of creation.

Regards.

Not applicable

Hello All,

Primary Key and Unique Key are both same and used as a unique identifiers.

only difference is that a primary key can not have a null value but the unique key can have that too only once.

Also you can have more than one UNIQUE constraint per table but in case of primary key

Not applicable

Primary Key: A column in a table whose values uniquely identify the rows in the table. A primary key value cannot be NULL.

Unique Key: Unique Keys are used to uniquely identify each row in a table. There can be one and only one row for each unique key value.

renjithpl
Specialist
Author

Thanks Karl, I got an idea about the topic.

Not applicable

Hi

Normal 0 false false false EN-US X-NONE X-NONE

Difference between Primary key and Unique key:

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.

siva_boggarapu
Creator II

Primary key is only one constraint per table and also unique also only one per table.

The main difference between primary key and unique key is primary key doesnot allow duplicate values where as uniques will allow one duplicate values(Sql server 2005 & 2008).

In Oracle Unique allows n no of null values. Becaue null!=null.