Sunday, December 11, 2022

SQL Server - Add Primary Key to Existing Table

Q. How to add Primary Key to an Existing Table?

Ans...

The Simple steps to add Primary Key / Clustered Index over existing table.

USE [DairyShop]

CREATE TABLE MILK_Transactions
(ID int Identity(1,1),
Customer_ID nvarchar(50),
CustomerName varchar(100),
SoldQty_in_Ltr tinyint,
Per_Ltr_PriceRs decimal(10,2),
AmountRs decimal(10,2),
Payment_Mode char(25)
)

ALTER Table MILK_Transactions add primary key (ID)

Best Regards

Amit Vaid

No comments: