primary key
A primary key is used to uniquely identify all table records.
It cannot have NULL values and must contain unique values.
A table can have only one primary key that consists of single or multiple fields.
unique key
The key that can accept only a null value and cannot accept duplicate values is called a unique key.
The role of a unique key is to make sure that all columns and rows are unique.
foreign key
A foreign key is an attribute or a set of attributes that reference the primary key of some other table. Basically, a foreign key is used to link together two tables.
What is the difference between primary key and unique key?
Both primary and unique keys carry unique values but a primary key can not have a null value, while a unique key can. In a table, there cannot be more than one primary key, but there can be multiple unique keys.
No comments:
Post a Comment