sql server 判断及增加列的默认值约束
时间:2021-07-01 10:21:17
帮助过:4人阅读
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
sql server 判断及增加列的默认值约束
标签: