When to use Primary key and Unique key
When to use Primary key and Unique key ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Neha SharmaPosted Jan 3, 2013, 3:03 AM
Ashutosh SharmaPosted Jan 13, 2013, 3:06 AM
Neha SharmaPosted Jan 5, 2013, 1:02 AM
Vishnujeet KumarPosted Jan 5, 2013, 12:10 AM
One more important scenario, if you want set references as foreign key ,then you have only one option first create primary key .
Vithal WadjePosted Jan 4, 2013, 11:15 PM
satish babuPosted Jan 4, 2013, 6:36 AM
Neha SharmaPosted Jan 3, 2013, 4:47 AM
Vithal WadjePosted Jan 3, 2013, 4:41 AM
my question is that in which situation i need to allow one null value that is which situation i need a uniqe key to apply...
any real time example you can explain
Jignesh TrivediPosted Jan 3, 2013, 1:56 AM
Both Primary and Unique Keys are enforce uniqueness of the column.
Primary Key creates clustered index by default and doesn't allow nulls.
Unique Key creates non-clustered index by default and allows only one null value.
you can choose any one from PK and Unique key but as you know table contain only one PK so if you required Uniquness on other column also then you may use Unique key on that column.
hope this will help you.
sathish kumarPosted Jan 3, 2013, 1:17 AM
When u want to have one NULL values in ur data u can use UNIQUE KEY . Because Unique key can accept one NULL value.
But in t case of Primay key, it doesnt accept any NULL value. So when u dont want being entered NULL values in ur table u can use PRIMARY KEY..
Hope this will be helpful for u.....
Satyapriya NayakPosted Dec 26, 2012, 5:48 AM
http://www.1keydata.com/sql/sql-unique.html