sql server 判断及增加列的默认值约束
IF NOT EXISTS ( SELECT name FROM sysobjects WHERE id = ( SELECT syscolumns.cdefault FROM sysobjects INNER JOIN syscolumns ON sysobjects.Id=syscolumns.Id WHERE sysobjects.name=N'tableName' AND syscolumns.name=N'columnName' ) ) BEGIN ALTER TABLE tableName add constraint DF_columnName DEFAULT N'N' for columnName; PRINT N'New add DF_columnName'; END ELSE BEGIN PRINT N'DEFAULT FOR columnName HAD EXISTS'; END
posted on 2015-06-09 10:02 freeliver54 阅读(4376) 评论(0) 编辑 收藏 举报