How can I create a unique constraint on my column in SQL Server?

The UNIQUE constraint ensures that all values in a column are different.
Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a column or set of columns.
A PRIMARY KEY constraint automatically has a UNIQUE constraint.
However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.


CREATE TABLE Persons (
    ID int NOT NULL UNIQUE,
    LastName varchar(255NOT NULL,
    FirstName varchar(255),
    Age int
);

SQL UNIQUE Constraint on ALTER TABLE


ALTER TABLE Persons
ADD UNIQUE (ID);

Comments

Popular posts from this blog

What is the difference between asynchronous and synchronous execution?

Yahoo accepting requests for inactive email IDs

How to install JDK 1.7.0 and how to set path and classpath variables