What is a Unique Key?
Let’s consider one example of books in the library. In the library, each book has a unique identification number called ISBN(International Standard Book Number). Just like how each book in the library has its own ISBN which ensures that no two books are similar. In the same way in the database of customers, everyone has their unique email id so from that we can get to know about that customer in detail. So these examples illustrate the concept of unique identification in a database system. So ISBN for the book and email ID for a customer here work as a unique key.
Example:
Roll_no. |
Name |
Address |
Personal_id |
---|---|---|---|
1 |
John |
Pune |
John@123 |
4 |
Merry |
Mumbai |
NULL |
18 |
Sheero |
Nagpur |
32467 |
20 |
Bisle |
Bengaluru |
B@127 |
In the above example, Roll_no can act as a primary since it is unique and there is no null value. Personal_id can act as a unique key because it is also unique and for one time we can keep its value as null so Personal_id is a unique key.
Unique Key in DBMS
A column or set of columns in a database system that uniquely identifies each tuple in the table is called a unique key. A unique key ensures that no two rows in the table have the same combination of values, so it enforces data integrity by preventing duplicity of the values in the table. In this article, we are going to see about the unique keys in DBMS along with their implementation in the table. Let’s start with the definition of a unique key.