sqlserver添加查询 表、字段注释,组合查询所有的用户、表名、表注释

一、此段转载:

1、sqlserver用语句给表注释
EXECUTE sp_addextendedproperty N'MS_Description', N'表注释', N'user', N'dbo', N'table', N'表名', NULL, NULL
2、sqlserver用语句给表的“字段”注释
EXECUTE sp_addextendedproperty N'MS_Description', N'字段注释', N'user', N'dbo', N'table', N'表名', N'column', N'字段名'
3、查看sqlserver注释
SELECT
A.name AS table_name,
B.name AS column_name,
C.value AS column_description
FROM sys.tables A
INNER JOIN sys.columns B ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
WHERE A.name = '表名'

二、组合查询所有的用户、表名、表注释
此处之前找了好多文档才搞定,所以特地分享出来
SELECT a.name as TABLE_NAME ,(SELECT name FROM sys.schemas s WHERE s.schema_id = a.uid) OWNER,cast((SELECT value FROM sys.extended_properties s1 WHERE s1.major_id = a.id) as varchar(500)) COMMENTS FROM SysObjects a Where XType='U' and (SELECT name FROM sys.schemas s WHERE s.schema_id = a.uid) in ('dbo[此处是对应的用户]') ORDER BY Name

你可能感兴趣的:(sqlserver添加查询 表、字段注释,组合查询所有的用户、表名、表注释)