23 January 2014

How to Drop Primary Key Constraint

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