Unique Key in RDBMS

RDBMSDatabaseMySQL

Many users consider Primary Key as Unique Key, since both uniquely identify a table, but Unique Key is different from Primary Key. Unique Key accepts null values and Primary Key cannot have null.

Let us compare Primary Key and Unique Key and understand its concept −

Usage

A Unique Key is used to prevent duplicate values in a column. Primary Key provided uniqueness to a table.

NULL Values

A primary key cannot accept NULL values; this makes Primary Key different from Unique Key, since Unique Key allows one value as NULL value.

Volume

A table can only have a single Primary Key, whereas a Unique Key can be more than one if you need it in the table.

Duplication

Unique Key ensures that data is not duplicated in two rows in the database. A row in the database can have null in case of Unique Key.

Modification

You cannot modify a Primary Key, but a Unique Key can be modified.

raja
Published on 04-Jul-2018 14:00:36
Advertisements