修改数据库列的默认值

DECLARE @table_ID INT,@column_id INT,@DF_QGovID NVARCHAR(max),@sql NVARCHAR(max)
SELECT @table_ID=tab.object_id FROM sys.tables tab WHERE name = 'EMS_AnnouncedCandidateDetail'
SELECT @column_id=column_id FROM sys.columns WHERE name = 'QGovID' AND object_id = @table_ID
SELECT @DF_QGovID=name FROM sys.default_constraints WHERE parent_column_id = @column_id AND parent_object_id = @table_ID
set @sql = N'
ALTER TABLE EMS_AnnouncedCandidateDetail DROP CONSTRAINT ['+@DF_QGovID+']
ALTER TABLE EMS_AnnouncedCandidateDetail ADD CONSTRAINT ['+@DF_QGovID+'] DEFAULT('''') FOR QGovID';
exec ( @sql );

 

posted @ 2020-01-15 14:18  穷且益坚不坠青云之志  阅读(488)  评论(0编辑  收藏  举报