Mark As Completed Discussion

UNIQUE Constraint

The UNIQUE constraint states that no cell value in a column may be used more than once across the whole table. To put it another way, there can be no duplicate rows in this column of the table. A guarantee for uniqueness for a column or set of columns is provided by the UNIQUE and PRIMARY KEY constraints. Let us now create the same table as above, only this time let’s add another condition that the Customer_Id has to be unique, apart from not being null:

TEXT/X-SQL
1CREATE TABLE Customer (
2    Customer_Id int NOT NULL UNIQUE
3);

If we’d like to ALTER an already created table, we’d use the ADD keyword this time instead of the MODIFY one. Let’s take a look:

TEXT/X-SQL
1ALTER TABLE Customer
2ADD Unique(Customer_Id);