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
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
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
alter table ghy888 drop column ghy1