How to drop a column which is primary key.. | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

How to drop a column which is primary key..

Hi All, I have created a temp column with primary key and identity column. After doing certain operation I need to delete the tempColumn(primary key and identity column).How to do it. I tried to do so by Alter table table1 drop columnname.But it is throwing error. can you please tell me how to do it. Thanks Surjit
Post the code you used and the error message you received
Do you want to reset the value? Madhivanan Failing to plan is Planning to fail
You need to drop the PRIMARY KEY constraint first. Then you can drop the column. —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by Madhivanan</i><br /><br />Post the code you used and the error message you received<br />Do you want to reset the value?<br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br /><br /><br />Hi Madhivanan,<br /><br />The code goes like this<br /><br />Alter table t2 drop aaaa — here t2 is tablename,aaaa is the column name which is a primary key.<br /><br />the error<img src=’/community/emoticons/emotion-7.gif’ alt=’:S’ />erver: Msg 3728, Level 16,state 1, Line 1<br />’aaaa’ is not a constraint.<br />Server: Msg 3727,Level 16, State 1,Line 1<br />Could not drop constraint.See previous errors<br /><br />Let me tell you why i need to add a primary key and again delete it<br /><br />I have a source table and a dataset(datatable) of that source table.I changed the dataset(datatable) and require to update the source table with the changed dataset.The problem is the source table donot have primary key. How can I update the table.Is it possible through stored procedure and how?<br /><br />In simple word I have table Table1 and copy of table table as TableCopy.I changed some value of TableCopy. I need update Table1 with values of Tablecopy.The table1 donot have primary key.How to do it<br /><br />Please let me know if the question is not clear.<br /><br />Surjit<br /><br />
You’re missing something like
ALTER TABLE t2 DROP CONSTRAINT <constraint name>
ALTER TABLE t2 DROP COLUMN aaaa —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs
]]>