Differentiate between primary key constraint and unique constraint. Why is unique constraint preferred over primary key constraint?

Database Management System >   Database Constraints >   Constraints Introduction  

Long Question

449


Answer:

The primary key constraint ensures that the attributes, which are declared as primary keys must be unique and not null. The primary key constraint enforces entity integrity for the relation and constrains the relation in the following ways:

  • The primary key attribute must have unique set of values for all the tuples in a relation.
  • The primary key attribute cannot have null value.
  • A relation can have only one primary key attribute.

The unique constraint ensures that a particular set of attributes contains unique values and hence, two tuples cannot have duplicate values in specified attributes. Like primary key, it also enforces entity integrity.

Unique constraint is preferable over primary key constraint to enforce uniqueness of a non-primary key attribute. This is because

  • Multiple unique constraints can be applied on a relation whereas only one primary key constraint can be defined on a relation.
  • Unlike primary key constraint, unique constraint allows the attribute value to be null.


This Particular section is dedicated to Question & Answer only. If you want learn more about Database Management System. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.