0 votes
in Sql by
What is a unique key?

1 Answer

0 votes
by
A unique key is a single or combination of fields that ensure all values stores in the column will be unique. It means a column cannot stores duplicate values. This key provides uniqueness for the column or set of columns. For example, the email addresses and roll numbers of student's tables should be unique. It can accept a null value but only one null value per column. It ensures the integrity of the column or group of columns to store different values into a table.

We can define a foreign key into a table as follows:

CREATE TABLE table_name(    

    col1 datatype,    

    col2 datatype UNIQUE,    

    ...    

);
...