UNIQUE Constraint In SQL
UNIQUE Constraint In SQL:-
How to create UNIQUE Constraint on CREATE TABLE in SQL:-
Alter UNIQUE Constraint on the table in SQL:-
How To DROP a UNIQUE Constraint in SQL:-
- The UNIQUE constraint uniquely identifies each record in a database table.
- The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns.
- A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it.
How to create UNIQUE Constraint on CREATE TABLE in SQL:-
CREATE TABLE tblEmpRecord ( EmpId int NOT NULL UNIQUE, FirstName varchar(200), LastName varchar(100) NOT NULL, Email varchar(MAX), Address nvarchar(200), City varchar(200) )
Alter UNIQUE Constraint on the table in SQL:-
------------For single column------------------- ALTER TABLE tblEmpRecord ADD UNIQUE(City) ------------For multiple columns---------------- ALTER TABLE tblEmpRecord ADD CONSTRAINT uc_EmpId UNIQUE (FirstName,LastName)
How To DROP a UNIQUE Constraint in SQL:-
ALTER TABLE tblEmpRecord DROP CONSTRAINT uc_EmpId