为SQL Server表中的列添加/修改/删除注释属性(sp_addextendedproperty、sp_updateextendedproperty、sp_dropextendedproperty)
本篇基本完全参考:sql--sp_addextendedproperty和sp_updateextendedproperty (Transact-SQL)
三个存储过程用法一样,以sp_addextendedproperty为例:
sp_addextendedproperty [ @name = ]{ ‘property_name‘ } [ , [ @value = ]{ ‘value‘ } [, [ @level0type = ]{ ‘level0_object_type‘ } , [ @level0name = ]{ ‘level0_object_name‘ } [, [ @level1type = ]{ ‘level1_object_type‘ } , [ @level1name = ]{ ‘level1_object_name‘ } [, [ @level2type = ]{ ‘level2_object_type‘ } , [ @level2name = ]{ ‘level2_object_name‘ } ] ] ] ]
参数:
if exists(select 1 from sys.tables where object_id=object_id(‘TestTable‘)) begin drop table TestTable end create table TestTable ( ColumnA varchar(50), ColumnB varchar(50) )
2.为ColumnA列添加注释:
exec sp_addextendedproperty @name=N‘MS_Description‘, @value=N‘列A的注释‘, @level0type=N‘SCHEMA‘, @level0name=N‘dbo‘, @level1type=N‘TABLE‘, @level1name=N‘TestTable‘, @level2type=N‘COLUMN‘, @level2name=N‘ColumnA‘
3.查看结果:
或者执行sql语句:
select B.Name,A.value from sys.extended_properties A inner join sys.columns B on A.major_id=B.object_id and A.minor_id=B.column_id where A.major_id=object_id(‘TestTable‘)
结果:
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。