Sql Server 添加、更新、查询表注释、字段注释相关sql


/*******************字段添加注释*********************/ if not exists (SELECT C.value AS column_description FROM sys.tables A INNER JOIN sys.columns B ON B.object_id = A.object_id INNER JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id WHERE A.name = N'表名' and B.name=N'字段名') 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'字段名' EXEC sp_updateextendedproperty @name=N'MS_Description', @value=N'字段注释' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'表名', @level2type=N'COLUMN',@level2name=N'字段名' /*******************表添加注释*********************/ if not exists (SELECT A.name, C.value FROM sys.tables A inner JOIN sys.extended_properties C ON C.major_id = A.object_id and minor_id=0 WHERE A.name = N'表名') EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'表注释' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'表名' EXEC sp_updateextendedproperty @name=N'MS_Description', @value=N'表注释' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'表名' /*******************查询注释相关sql***********************/ --查看表的注释 SELECT A.name, C.value FROM sys.tables A inner JOIN sys.extended_properties C ON C.major_id = A.object_id and minor_id=0 WHERE A.name = N'表名' --查看字段的注释 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 = N'luobo'

  

原文地址:https://www.cnblogs.com/straw/p/5964899.html