SQL Server UNIQUE constraint



SQL Server UNIQUE constraints allow you to ensure that the data stored in a column, or a group of columns, is unique among the rows in a table

CREATE TABLE user(
id INT IDENTITY PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255),
UNIQUE(email)
);

If you enter a duplicate email id in the database, the error will show.
Violation of UNIQUE KEY constraint 'UQ__user__AB23436417240E4E'. Cannot insert duplicate key in object 'user'. The duplicate key value is (test@gmail.com)

0 Comment's

Comment Form