sqlserver新增查詢 表、欄位註釋,組合查詢所有的使用者、表名、表註釋

weixin_34138377發表於2017-12-04

一、此段轉載:

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

相關文章