UNIQUE KEY



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.


SQL UNIQUE KEY constraint on CREATE TABLE-(Defining a unique key constraint on single column):
Syntax
CREATE TABLE students  
(  
S_Id int NOT NULL UNIQUE,  
LastName varchar (255) NOT NULL,  
FirstName varchar (255),  
City varchar (255)  
)  
(Defining a unique key constraint on multiple columns):
 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)  
)  
SQL UNIQUE KEY constraint on ALTER TABLE-(Defining a unique key constraint on single column)
Syntax
ALTER TABLE students  
ADD UNIQUE (S_Id)  
(Defining a unique key constraint on multiple columns):
ALTER TABLE students  
ADD CONSTRAINT uc_StudentId UNIQUE  (S_Id, LastName)

Connection String

SQL Server Connection String Formats

posted on 2019-08-27 05:53:53 - SQL Server Tutorials


UNION

union in SQL server

posted on 2019-08-09 23:05:33 - SQL Server Tutorials


System Functions

System Functions in SQL Server

posted on 2019-08-09 06:14:33 - SQL Server Tutorials


Prompt Examples

ChatGPT Prompt Examples

posted on 2023-06-21 22:37:19 - ChatGPT Tutorials


Use Cases

Chat GPT Key Use Cases

posted on 2023-06-21 21:03:17 - ChatGPT Tutorials


Prompt Frameworks

Prompt Frameworks

posted on 2023-06-21 19:33:06 - ChatGPT Tutorials