+ 3

What is the difference between unique and primary key?

25th Oct 2016, 7:12 AM
Ajay Nagaram
Ajay Nagaram - avatar
11 Antworten
+ 10
let's start with a fact alright , primary key is unique and not null but every unique key and not null key cannot be a primary key... for example in a company's database ,employee ID can be kept as a primary key but his Mobile number is usually kept as a unique key and not primary key. Because no two employees can have same mobile number therefore they should be unique and not null but since employee ID is more suitable to keep as primary key, we do It That Way... I hope this gives you answer. And bonus one, you can only have one primary key in a table but you can have multiple unique keys in a table...
21st Nov 2016, 6:05 AM
AsHish NiGam
AsHish NiGam - avatar
+ 3
You can only have one primary key per table, and it is a unique key not accepting null values. @Sanoj: You may have several null values in a unique column.
25th Oct 2016, 8:41 AM
Zen
Zen - avatar
+ 1
primary key is one of the unique column of table that can't have null value and it can index every row in a table
25th Oct 2016, 11:08 AM
babakm
babakm - avatar
+ 1
and unique is a constraint that you can use in others columns to force the data be unique
1st Nov 2016, 1:44 PM
Ronald Serrão
Ronald Serrão - avatar
+ 1
all primary keys are unique but not all unique are primary keys.
3rd Nov 2016, 1:54 AM
Erik Winar
Erik Winar - avatar
+ 1
u can only use one primary key in a table while u can use multiple unique key in a table.. :)
21st Nov 2016, 3:46 AM
Arun Bhandari
Arun Bhandari - avatar
+ 1
primary key unique and not null (no redundancies no null values) and have vital role in the tables relationship .... unique (no redundancies)
15th Jan 2017, 8:50 AM
Mahmoud El Menshawy
Mahmoud El Menshawy - avatar
+ 1
Primary Key is like your driver's license number: it is unique, and it won't ever change or be used for anybody else. So, if you are to choose between using one's ID number and one's cell phone number as primary key, you should choose using the ID number, as it is possible that you change your cell phone number but your ID number is Unique and it won't ever change.
18th Jan 2017, 8:42 AM
Kenshin
Kenshin - avatar
0
primary key can't have null value while unique can have only one null value so that the column can be uniquely defined.
25th Oct 2016, 7:52 AM
Sanoj Chourasia
Sanoj Chourasia - avatar
0
primary key does not null values and duplicate values but where unique key means not allow duplicates value...
29th Oct 2016, 3:22 AM
pramod
0
primary key has clusters index on it and it can be Va foreign key for other table. Not null can't.
29th Oct 2016, 5:36 AM
Nidhi
Nidhi - avatar