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

How to Drop Primary Key Constraint


Database Database 
Ratings:
0 Comment(s)
 3090  View(s)
Rate this:

How to Drop Primary Key Constraint

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

 

 


Don't want to miss updates? Please click the below button!

Follow MindStick