UNIQUE KEY in SQL Server Database Table
A unique key is a set of one or more than one fields/columns of a table that uniquely identify a record in a database table.
* The unique key and primary key both provide a guarantee for uniqueness for a column or a set of columns.
* There is an automatically defined unique key constraint within a primary key constraint.
* There may be many unique key constraints for one table, but only one PRIMARY KEY constraint for one table.
CREATE TABLE students
(
S_Id int NOT NULL UNIQUE,
LastName varchar (255) NOT NULL,
FirstName varchar (255),
City varchar (255)
)
CREATE TABLE students
(
S_Id int NOT NULL,
LastName varchar (255) NOT NULL,
FirstName varchar (255),
City varchar (255),
CONSTRAINT uc_studentId UNIQUE (S_Id, LastName)
)
ALTER TABLE students
ADD UNIQUE (S_Id)
ALTER TABLE students
ADD CONSTRAINT uc_StudentId UNIQUE (S_Id, LastName)
SQL Server Connection String Formats
posted on 2019-08-27 05:53:53 - SQL Server Tutorials