欢迎投稿

今日深度:

SQL_为表和列加注释,sql注释

SQL_为表和列加注释,sql注释


***********************************************声明*********************************************************************** 

原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处,否则追究版权法律责任。

深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/39755221

****************************************************************************************************************************

1. 表级

(1)、对表进行注释:
SQL>comment on table <表名> is <'正文'>;
--小写格式
SQL>COMMENT ON TABLE <表名> IS <'正文'>;
--大写格式
(2)、查看表的注释:
SQL>select comments from user_tab_comments where table_name='表名';
--小写格式
SQL>SELECT COMMENTS FROM user_tab_comments  WHERE TABLE_NAME='表名';
--大写格式
(3)、样例

SQL> comment on table dept is 'scotts deptno table' ;
Comment added
SQL> select comments from user_tab_comments where table_name='DEPT';
COMMENTS
--------------------------------------------------------------------------------
scotts deptno table

2. 列级

(1)、对列进行注释:
SQL>comment on column <表名.列名> is '正文';
--小写格式
SQL>COMMENT ON COLUMN <表名.列名> IS '正文';
--大写格式
(2)、查看列的注释:
SQL>select comments from user_col_comments where table_name='表名' and column_name='列名';
--小写格式
SQL>SELECT COMMENTS FROM user_col_comments WHERE TABLE_NAME='表名' AND COLUNM_NAME='列名';
--大写格式
(3)、样例

SQL> comment on column dept.dname is ' scotts table mean column which name is depts name ';
Comment added
SQL> select comments from user_col_comments where table_name='DEPT' and column_name='DNAME';
COMMENTS
--------------------------------------------------------------------------------
 scotts table mean column which name is depts name

***********************************************声明*********************************************************************** 

原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处,否则追究版权法律责任。

深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/39755221

****************************************************************************************************************************


怎在SQL Server 中添加注释

-- 表加注释
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'字段名'
 

怎获取SQL表字段的注释文本

WHERE (B.id = OBJECT_ID('表名称'))SQL2005:select * from fn_listextendedproperty('MS_Description', 'user', 'dbo', 'table', '表名称'', 'column', default)
注:次方法只能取出有注释的字段,如果指定表没有注释,则此方法不能获取到任何记录
 

www.htsjk.Com true http://www.htsjk.com/shujukunews/3632.html NewsArticle SQL_为表和列加注释,sql注释 ***********************************************声明*********************************************************************** 原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务...
评论暂时关闭