primary key and unique key in sql which is better
primary key and unique key in sql which is better. Please give me a example. Its very urgent.
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.
Ranjit PowarPosted Dec 31, 2014, 3:13 AM
If you use primary key then you are not able to insert null value.
Sibeesh VenuPosted Dec 31, 2014, 2:27 AM
Unique Example:
1
2
NULL
3
4
NULL (This will throw constraint violation error as it will be duplicate)
4 (This will also throw constraint violation error as it will be duplicate)
Primary key Example:
1
2
NULL (This will throw constraint violation error)
3
4
4 (This will also throw constraint violation error as it will be duplicate)
And it is always based on your requirement . Please read here for more info
http://www.programmerinterview.com/index.php/database-sql/differences-between-primary-and-foreign-keys/
Please accept and up vote
Kindest Regards
Sibeesh
http://sibeeshpassion.com/