如何在SQL Server 中添加注释
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在SQL Server 中添加注释相关的知识,希望对你有一定的参考价值。
我想在我建立表的列名那 添加中文注释 请教高手!
首先,要明确一点的是注释存在sysproperties表中而不是跟创建的表捆绑到一起的具体使如方法如下:
一、使用SQL Server窗口创建表是会有注释窗口;
二、使用SQL语句的comment语句,该语句放置在create table()后面,如:
comment on table table_name is \'table_mark\'
comment on column table_name."Column" is \'column_mark\'
三、调用系统存储过程sp_addextendedproperty来添加注释,如:
EXECUTE sp_addextendedproperty N\'MS_Description\',N\'雇员信息\',N\'user\',N\'dbo\',N\'table\',N\'Employee\',NULL,NULL
EXECUTE sp_addextendedproperty N\'MS_Description\',N\'主键ID,自动增加\',N\'user\',N\'dbo\',N\'table\',N\'Employee\',N\'column\',N\'EmployeeID\'
或者
EXEC sys.sp_addextendedproperty @name=N\'MS_Description\', @value=N\'角色ID\' , @level0type=N\'SCHEMA\',@level0name=N\'dbo\', @level1type=N\'TABLE\',@level1name=N\'CharData\', @level2type=N\'COLUMN\',@level2name=N\'charid\'
GO 参考技术A -- 表加注释
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'注释内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=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'字段名' 参考技术B 格式一:/*注释文本*/
格式2:--注释文本
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 Server 抛出查询时,如何在 Access 中留下 SQL 注释?
如何将架构绑定添加到 SQL Server 2008 中的视图