Click here to Skip to main content
15,914,924 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Any one please explain the difference between Primary and unique keys with an example.
Posted

The only difference is unique can contain one null value where as primary key cannot contain any null.

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)
 
Share this answer
 
v2
Comments
DileepReddyC 27-Sep-13 6:32am    
thank u
ArunRajendra 27-Sep-13 6:48am    
Welcome
 
Share this answer
 
Comments
DileepReddyC 27-Sep-13 6:31am    
thank u
[no name] 27-Sep-13 6:33am    
Welcome..please accept the solution if it's helpful.so that it will be helpful for others..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900