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.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sibeesh VenuRank #27 · 42.9K reputationPosted Dec 30, 2014, 9:27 PM EST
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/
Ranjit PowarRank #553 · 4.4K reputationPosted Dec 30, 2014, 10:13 PM EST
If you use primary key then you are not able to insert null value.