SQL Server Transact Basic to Expert - Unique Constraints Query

This blog shows how to create a unique constraint in a table, Unique constraints are used to enforce a uniqueness to a table some thing related to a primary key. A table can have a single Primary Key to maintain a column uniqueness we can use the Unique constraint as shown below

Syntax:

Create Table tablename
(Column1 Datatype Null/Not Null Primary key,
 Column2 Datatype Null/Not Null,
 Column3 Datatype Null/Not Null Unique
)

Example:

Create Table emptable
(empid int Not Null Primary key,
 empname Varchar(50) Not Null,
 empBAID int Not Null Unique
)

Ebook Download
View all
Learn
View all