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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 dropping a column with a constraint

Author  Topic 

mdhingra01
Posting Yak Master

179 Posts

Posted - 2004-08-27 : 15:12:14
How do you drop a column that has a constraint attached to it?

This is my code to create the extra column with the constraint.
ALTER TABLE MyTable
ADD AddDate smalldatetime NULL
CONSTRAINT AddDateDflt
DEFAULT getdate() WITH VALUES

Now I want t drop this extra column. Please help.

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-08-27 : 15:18:42
Drop the constraint, then drop the column. You can drop a constraint with ALTER TABLE.

Tara
Go to Top of Page

mdhingra01
Posting Yak Master

179 Posts

Posted - 2004-08-27 : 15:20:07
Thanks Tara. That worked!
Go to Top of Page

mdhingra01
Posting Yak Master

179 Posts

Posted - 2004-08-27 : 15:21:40
If I am interested in adeding the new column back to the table, but in the in the first column as opposed tot he last column, is this possible?

Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-08-27 : 15:28:50
Yes, but you can't do it with ALTER TABLE. You have to create a new table that has the table ordered how you want it to be. Then you have to move your data to this new table. Then drop the old table. Then rename the new table to the old table's name. Don't forget constraints and indexes on the new table.

Tara
Go to Top of Page
   

- Advertisement -