Categories
Sql Server

How to create PRIMARY KEY constraints In Sql server

Primary Key Constraints

The PRIMARY KEY constraint uniquely identifies record in a database table.

Primary key column cannot have NULL values.

Query:-

The below following query a primary key in id column.

create table account3
( 
id int primary key,
Firstname varchar(50),
Lastname varchar(50)
)

To create a PRIMARY KEY on a already created table , use the following query:
alter table account3
add primary key(id)

Note:- No primary key already created on that table.