首页 > 数据库 > SQL Server > 正文

sql server 判断及增加列的默认值约束

2024-08-31 00:54:21
字体:
来源:转载
供稿:网友
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';ENDELSEBEGIN    PRINT N'DEFAULT FOR columnName HAD EXISTS';END


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表