当前位置: 移动技术网 > IT编程>数据库>Oracle > oracle comment命令用法示例分享

oracle comment命令用法示例分享

2017年12月12日  | 移动技术网IT编程  | 我要评论

oracle中用comment on命令给表或字段加以说明,语法如下:

复制代码 代码如下:

comment on
  { table [ schema. ]
    { table | view }
  | column [ schema. ]
    { table. | view. | materialized_view. } column
  | operator [ schema. ] operator
  | indextype [ schema. ] indextype
  | materialized view materialized_view
  }
is 'text' ;

用法如下:

1.对表的说明

复制代码 代码如下:

comment on table table_name is 'comments_on_tab_information';

2.对表中列的说明

复制代码 代码如下:

comment on column table.column_name is 'comments_on_col_information';

3.查看表的说明

复制代码 代码如下:

sql> select * from user_tab_comments where table_name='employees';

复制代码 代码如下:

table_name                     table_type  comments
------------------------------ ----------- ----------
employees                      table       员工表

sql> select * from user_tab_comments where comments is not null;

table_name                     table_type  comments
------------------------------ ----------- --------------------------
employees                      table       员工表

4.查看表中列的说明

复制代码 代码如下:

sql> select * from user_col_comments where table_name='employees';

复制代码 代码如下:

table_name                     column_name                    comments
------------------------------ ------------------------------ ------------
employees                      employee_id                   
employees                      manager_id                    
employees                      first_name                    
employees                      last_name                     
employees                      title                         
employees                      salary                         员工薪水


sql> select * from user_col_comments where comments is not null;

table_name                     column_name                    comments
------------------------------ ------------------------------ -------------
employees                      salary                         员工薪水

5.我们也可以从下面这些视图中查看表级和列级说明:

复制代码 代码如下:

all_col_comments
user_col_comments
all_tab_comments
user_tab_comments

6.删除表级说明,也就是将其置为空

复制代码 代码如下:

sql> comment on table employees is '';
comment added

sql> select * from user_tab_comments where table_name='employees';

table_name                     table_type  comments
------------------------------ ----------- -------------
employees                      table     

7.删除列级说明,也是将其置为空

复制代码 代码如下:

sql> comment on column employees.salary is '';
comment added

sql> select * from user_col_comments where table_name='employees';

table_name                     column_name                    comments
------------------------------ ------------------------------ -------------
employees                      employee_id                   
employees                      manager_id                    
employees                      first_name                    
employees                      last_name                     
employees                      title                         
employees                      salary

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网