Hello All, We are going to start new batch from next week. message/call or mail us for more details.

8 September 2013

How to Drop Primary Key Constraint - DotNet Brother

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

No comments:

Post a Comment