sqlserver批量更改所有表中相同字段的注释
时间: 2023-08-22 14:05:20 浏览: 156
你可以使用以下的SQL语句来批量更改SQL Server中所有表中相同字段的注释:
```
EXEC sp_MSforeachtable @command1='
IF EXISTS (
SELECT *
FROM sys.columns
WHERE object_id = object_id("?")
AND name = "YourColumnName"
)
BEGIN
EXEC sys.sp_addextendedproperty
@name = N"MS_Description",
@value = N"YourNewDescription",
@level0type = N"SCHEMA",
@level0name = N"dbo",
@level1type = N"TABLE",
@level1name = N"?" ,
@level2type = N"COLUMN",
@level2name = N"YourColumnName";
END
'
```
将上述代码中的 "YourColumnName" 替换为你希望更改注释的字段名,将 "YourNewDescription" 替换为你希望设置的新注释即可。
阅读全文