create table ghy888(
ghy1 char(10) default '1',
ghy2 int
)--删除一个字段前去掉默认值
declare @name varchar(2000)
select @name=b.name from syscolumns a,sysobjects b where a.id=object_id(N'ghy888') and b.id=a.cdefault and a.name='ghy1' and b.name like 'DF%'
exec('Alter table ghy888 drop constraint '+@name) 
alter table ghy888 drop column ghy1
GO
Select * from ghy888

解决方案 »

  1.   

    --删除多列create table ghy888(
    ghy1 char(10) ,
    ghy2 int,
    ghy3 int
    )
    GO
    Select * from ghy888
    alter table ghy888 drop column ghy1,ghy2
    GO
    Select * from ghy888
    GO
    Drop Table ghy888
      

  2.   

    这个是最简单的了。因为你的字段有默认值,所以要先找到该字段的constraintname,再Drop掉该constraint,最后再删除字段。如果你知道你的字段的constraintname的话,就简单了。但是通常情况下都会需要到数据库中去找到这个constraintname。
      

  3.   

    先取消这个默认值然后再执行
    alter table ghy888 drop column ghy1