Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Dropiing a primary key not working

Author  Topic 

tvspsekhar
Starting Member

20 Posts

Posted - 2010-03-18 : 02:38:29
please correct the follwoing syntax.

ALTER TABLE TOWERSCH DROP CONSTRAINT PRIMARY KEY(LOCNO);

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'PRIMARY'.

The above error message is coming on execution of the above statement.

tvspsekhar

raky
Aged Yak Warrior

767 Posts

Posted - 2010-03-18 : 02:46:58

You statement should be in the following format

ALTER TABLE <tablename> DROP CONSTRAINT <constraint Name>

Go to Top of Page

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-18 : 02:48:09
ALTER TABLE TOWERSCH
DROP CONSTRAINT LOCNO
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2010-03-18 : 02:55:30

first run this query

select name as 'constraint Name'
from sys.objects where type = 'pk'
and object_id('TOWERSCH') = parent_object_id

then

replace the <constraint name> in below statement

ALTER TABLE TOWERSCH DROP CONSTRAINT <constraint Name>

with the value returned by firstquery and execute.
Go to Top of Page

tvspsekhar
Starting Member

20 Posts

Posted - 2010-03-18 : 03:16:09
quote:
Originally posted by raky


first run this query

select name as 'constraint Name'
from sys.objects where type = 'pk'
and object_id('TOWERSCH') = parent_object_id

then

replace the <constraint name> in below statement

ALTER TABLE TOWERSCH DROP CONSTRAINT <constraint Name>

with the value returned by firstquery and execute.


Now it is working . Thank U Very Much

tvspsekhar
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2010-03-18 : 03:20:08
welcome...
Go to Top of Page
   

- Advertisement -