0

my table structure is as given below

create table qwe
(
id int primary key,
employee varchar(100)
)

How to delete Primary key from the ID column . I have tried the following :

alter table qwe
alter column id int

I know I can remove this key by going into design mode, but is there a way to delete using SQL statement.

sam
  • 1,242
  • 3
  • 12
  • 31

2 Answers2

1

Try this

ALTER TABLE qwe
DROP CONSTRAINT id

Drop primary key using script in SQL Server database

check this link http://www.w3schools.com/sql/sql_primarykey.asp

http://blog.sqlauthority.com/2009/05/12/sql-server-how-to-drop-primary-key-contraint/

Community
  • 1
  • 1
Ajay
  • 6,418
  • 18
  • 79
  • 130
0

Try this:

ALTER TABLE qwe DROP CONSTRAINT id;

In case this gives an error, try:

ALTER TABLE qwe NOCHECK CONSTRAINT id;
shauryachats
  • 9,975
  • 4
  • 35
  • 48
  • its giving me error: – sam Mar 18 '15 at 12:09
  • Msg 3728, Level 16, State 1, Line 2 'id' is not a constraint. Msg 3727, Level 16, State 0, Line 2 Could not drop constraint. See previous errors. – sam Mar 18 '15 at 12:09
  • i am still getting err – sam Mar 18 '15 at 12:14
  • Msg 4917, Level 16, State 0, Line 1 Constraint 'id' does not exist. Msg 4916, Level 16, State 0, Line 1 Could not enable or disable the constraint. See previous errors. – sam Mar 18 '15 at 12:14