Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a primary key and a unique constraint?

Someone asked me this question on an interview...

like image 829
Tim Avatar asked Aug 20 '09 20:08

Tim


People also ask

What is the difference between primary key and primary key constraint?

The main difference is that the primary key column can only be created when you create/add the table or column, not later. The primary key constraint you can add any time later.

What is the difference between primary key and UNIQUE constraint Mcq?

Primary key can store null value, whereas a unique key cannot store null value.

What is the difference between key and unique key?

A primary key is a column, or a combination of columns, that can uniquely identify a row. It is a special case of unique key. A table can have at most one primary key, but more than one unique key. When you specify a unique key on a column, no two distinct rows in a table can have the same value.


1 Answers

Primary keys can't be null. Unique keys can.

like image 51
Håvard Avatar answered Oct 14 '22 09:10

Håvard