Register now or log in to join your professional community.
Primary Key: A primary key is a single column or combination of columns that uniquely identifies a record. None of the columns that are part of the primary key can contain a null value.A table can have multiple unique and foreign keys. However, a table can have only one primary key.
Unique Key: A unique key or primary key [is a candidate key] to uniquely identify each row in a table. It can be comprised of either a single column or multiple columns. The major difference is that for unique keys the implicit NOT NULL constraint is not automatically enforced, while for primary keys it is enforced. Thus, the values in unique key columns may or may not be NULL.
Differences between Primary Key and Unique Key
1. Primary Key does not accept null value whereas Unique Keys accepts null value.
2. There will be only one primary key in a table whereas More than one unique key will be there in a table.
3. Clustered index is created in Primary key whereas Non-Clustered index is created in unique key.
4. Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist whereas unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values.
I found a good answer about question. You may read it http://stackoverflow.com/questions/707874/differences-between-index-primary-unique-fulltext-in-mysql
yes right answer. primary key is not allow null value but unique key allow null value.
Both are used for Unique Identification of data.But the Main difference is primary key won't allow null values but unique key will allow maximum one Null value.
In a table there can be only one primary key but you can have multiple unique keys not null
Primary Key: Only one/table ,unique,not null
Unique Key: can be many/table,allows null
Every primary is a unique but every unique is not primary
primary key=unique +not null.
unique key +not null=candidate key,
candidate keys are the nominies of primary key