1. 查询注释
查询表的所有注释
SELECT A.name ,C.value FROM sys.tables A LEFT JOIN sys.extended_properties C ON C.major_id = A.object_id WHERE C.minor_id=0 group by A.name ,C.value
查询表的所有字段注释
1 SELECT A.name AS table_name,B.name AS column_name,C.value AS column_description 2 FROM sys.tables A 3 INNER JOIN sys.columns B ON B.object_id = A.object_id 4 LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id 5 WHERE A.name = 't_bd_hobby' -- 表名
2. 添加表注释
1 -- 表加注释 2 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'注释内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'表名' 3 --例如: 4 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'系统设置表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CM01_SYSTEM'
3.添加字段注释
-- 字段加注释 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'注释内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'表名', @level2type=N'COLUMN',@level2name=N'字段名'
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/database/288036.html