articles

Home / DeveloperSection / Articles / How to Drop Primary Key Constraint

How to Drop Primary Key Constraint

AVADHESH PATEL 5460 27-Sep-2012

Here I described how to drop primary key form table. There are two way for doing this.

One is when we are not providing constraint key name during creating table.

Second is given constraint name during creating table.

Without giving constraint key 

First create a table in SQL server with primary key only like below code.

create table info

(
id int primary key,
[name] varchar(50) not null,
address varchar(50) not null
)

 Copy the key value from created table ‘Keys’. This key automatic created by sql server.

How to Drop Primary Key Constraint

Write code for drop primary key


alter table info 
drop PK__info__1A14E395

 With giving constraint key

Create table like below

create table info

(
id int,
[name] varchar(50) not null,
address varchar(50) not null
constraint pk_info_id primary key clustered(id asc)
)

 Drop primary key

alter table info

drop pk_info_id

 

 


Updated 07-Sep-2019
Avadhesh Kumar Patel District Project Manager - Aligarh 14 months work experience in Panchayati Raj Department Sector as District Project Manager & 12 months work experience in IT Sector as Software Engineer. :-)

Leave Comment

Comments

Liked By