T-SQL Tutorial

Create Table with Primary Key T-SQL


DDL statement - Create Table with Primary Key

To create a table with Primary Key you need to use create table command like in the below example.

Create Table with Primary Key

USE tempdb;
GO
CREATE TABLE Customers
(ID int,
Name varchar(500),
City varchar(500),
CONSTRAINT PK_Customers PRIMARY KEY (ID)
GO

Check if the primary key exists

select *
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where CONSTRAINT_TYPE='PRIMARY KEY';