5
Answers

What is difference between Primary Key and Unique Key in SQL

What is the difference between Primary Key and Unique Key in SQL? Please tell me in your words only. I request you don't post a link to read further.I need answer in simple way.

Answers (5)

2
Photo of Jaish Mathews
130 14.4k 2.2m 5y
Well explained in below loop. Now as an example for "Employee" table.
 
Column "Employee Id" can be Primary (no null, no duplicate, use as Ref. in other tables),
Column "Employee Number" can be Unique (no null as every one should have an employee number, no duplicate),
Column "Passport Number" can also be another Unique (can be null as some may not have passport, no duplicate)
Accepted
3
Photo of Rajanikant Hawaldar
32 38.8k 454.6k 5y
Hello Priyanka, 1)Primary Key never allow and accept null values. Unique Key can have only one null values. 2)Table can have only one Primary Key. Table can have more than one Unique Key. 3)Primary Key is Clustered Index. Unique Key is non-Clustered Index. 4)Primary Key Data in Database Table is Physically organized in the sequence because of Clustered Index. Unique Key Data is not Physically organized in the sequence. 5)Primary Key can make foreign key in another table. Unique Key can not be foreign key in another table.
1
Photo of Sanghdeep Sanghratne
NA 684 413.4k 5y
1) Primary key must have unique value, it never contain null value. Whereas unique key must have unique value, but it may have null value. 2) Primary key is used to identify a row or record in a table. Whereas unique key is assigned to the column, it prevents the duplicate values in column. 3) A table may have only one primary key but it may have more than one unique key.
0
Photo of Rajeev Kumar
737 1.2k 76k 2y

The primary key is accepted as a unique or sole identifier for every record in the table. In the case of a primary key, we cannot save NULL values. In the case of a unique key, we can save a null value, however, only one NULL value is supported

0
Photo of Priyanka Singh
673 1.4k 699.7k 5y
Thank you Jaish Mathews with the help of example I clearly clear my doubts.