Sql Server 添加更新查询表注释字段注释相关sql
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘
以上是关于Sql Server 添加更新查询表注释字段注释相关sql的主要内容,如果未能解决你的问题,请参考以下文章