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.
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