SQL Unique Constraint

18-07-2019  0 Comment(s)

SQL Unique Constraint will ensure that no duplicate values are inserted into the SQL table columns. For example, if we want to make sure that the Employee, or a customer has to login using single email address then we can assign a Sql Unique Constraint to that column.

In this article we will show you, how to create a Unique constraint in SQL server with examples.

Create SQL Unique Constraint

We can create a SQL Server Unique Constraint using both the Transact SQL query, and the Management Studio.

Creating SQL Unique Constraint using SSMS

In this example we will show you, How to create a Unique Constraint in SQL server using the SQL server management Studio. To do so, Please go to the Object Explorer.

Within the object explorer, Expand the Database folder in which our table located. Please select the table on which you want to create a Unique Constraint (here it is CustomerRecords), and Right click on it will open the context menu. Please select Design option as shown below

Once you click the Design option, SQL management studio will open the corresponding table in design mode. From the below screenshot you can observe that, We had 7 columns of different data types, and our task is to add the Unique Constraint to Email Address column. In order to create a SQL Unique constrain, Right click on the Column name, and select the Indexes/Keys.. option from the context menu.



Comment Here


No Comments to Show