sql删除带默认值的列

USE MyTestDB
--先删除约束
declare @name varchar(20)
select @name = b.name from sysobjects b join syscolumns a on
b.id = a.cdefault where a.id = object_id('UserInfo') and a.name = 'NickName'
exec('alter table UserInfo drop constraint ' + @name)

--然后再删除字段就OK了
ALTER TABLE dbo.UserInfo DROP COLUMN NickName

posted @ 2012-06-13 11:44  园封记忆  阅读(1625)  评论(0编辑  收藏  举报