0 votes
1.8k views
in MySQL by
What is difference between primary key and unique key ?

1 Answer

0 votes
by
There are following difference between Primary and unique key:-
 
1. Primary key does not allow null value but unique key allows null value.
2. We can declare only one primary key in a table but a table can have multiple unique keys(column assign).
3. The primary key is used to work with 2 or more different tables. This is the foundation of relational databases. 
For Example:- You have a book database and create 2 tables - 
  • books and 
  • authors with INT primary key "id". 
Then you use id in books instead of authors name.
 
The unique key is used if you don't want to have repeated entries only. 
For Example:- You may have title in your book table and want to be sure there is only one entry comes to title.

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...