How to DROP a PRIMARY KEY in MS SQL Server

Sometimes you may need to drop or delete primary key of a table in MS SQL Server. You can drop a primary key in SQL Server using the ALTER TABLE statement.

Let’s create a table first to demonstrate the example.

CREATE TABLE [DataAnalytics].[dbo].[tblt_emp]
emp_name VARCHAR(50) NOT NULL,
dob DATE,
age FLOAT,
income DECIMAL(10,2),
remarks NVARCHAR(500),
CONSTRAINT pk_tblt_emp_id PRIMARY KEY(id)

The syntax to drop a primary key using the ALTER TABLE statement in SQL Server is:

ALTER TABLE table_name
DROP CONSTRAINT constraint_name;

Let’s look at an example of how to drop a primary key using the ALTER TABLE statement in MS SQL Server.

ALTER TABLE [DataAnalytics].[dbo].[tblt_emp]
DROP CONSTRAINT pk_tblt_emp_id;

After executing the above statement you will see a successful message of executing the drop constraint statement.

I have an another tutorial similar to this tutorial where you will learnĀ How To DISABLE a PRIMARY KEY in MS SQL Server.

In this tutorial, I have shown how to drop primary key in MS SQL Server. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page and stay connected.

Add a Comment