欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

oracle comment命令用法示例分享

程序员文章站 2023-11-25 17:05:34
oracle中用comment on命令给表或字段加以说明,语法如下:复制代码 代码如下:comment on  { table [ schema. ] ...

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