ALTER TABLE DROP CONSTRAINT DF_Users_salary ALTER TABLE DROP COLUMN salary
if object_id('test')>0 drop table test go create table test(id int not null,age int null default(20)) go insert test(id) select 1 insert test select 2,22 go select * from test /* id age 1 20 2 22 */declare @table sysname,@col sysname,@constraint_name sysname select @table='test',@col='age' select @constraint_name=b.name from sys.syscolumns a join sys.sysobjects b on a.cdefault=b.id where object_id(@table)=a.id and a.name=@col and a.cdefault>0 if @constraint_name is not null exec('alter table test drop '+@constraint_name)alter table test drop column age go select * from test /* id 1 2 */
ALTER TABLE DROP COLUMN salary
drop table test
go
create table test(id int not null,age int null default(20))
go
insert test(id) select 1
insert test select 2,22
go
select * from test
/*
id age
1 20
2 22
*/declare @table sysname,@col sysname,@constraint_name sysname
select @table='test',@col='age'
select @constraint_name=b.name from sys.syscolumns a
join sys.sysobjects b on a.cdefault=b.id
where object_id(@table)=a.id and a.name=@col and a.cdefault>0
if @constraint_name is not null
exec('alter table test drop '+@constraint_name)alter table test drop column age
go
select * from test
/*
id
1
2
*/