Categories
Sql Server

How to create UNIQUE constraints In Sql server

The UNIQUE constraint uniquely identifies each record in a database table.

The UNIQUE constraints provide a guarantee for uniqueness for a column or set of columns.

Query:-

CREATE TABLE ACCOUNT2
(
P_Id int NOT NULL UNIQUE,
LastName varchar(50) NOT NULL,
FirstName varchar(50),
Address varchar(255)
)

To create a UNIQUE constraints in already created table use following query:-

ALTER TABLE account2
ADD constraint ck_first UNIQUE (FirstName)

To Drop already created constraints use the following query:-

ALTER TABLE account2
DROP constraint ck_first