Database – Two Ways to Add a Primary Key Constraint in MSSQL

Add column and constraint in one step

ALTER TABLE employees

ADD EmployeeID INT IDENTITY(1000, 1) PRIMARY KEY;

Add column constraint in two steps

ALTER TABLE employees
ADD EmployeeID INT IDENTITY(1000,1);

ALTER TABLE employees
ADD CONSTRAINT PK_EmployeeID PRIMARY KEY (EmployeeID);

Leave a Reply

Your email address will not be published. Required fields are marked *