一、comment是oracle数据库系统的关键字,用于对表,字段添加注释,有利于用户对表结构以及数据库对象含义的理解。
语法如下:
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';
二、用户可以通过数据字典视图来查询表或字段的注释信息,可查询的相应视图为:
1. 访问自己用户的注释信息要查询的数据字典视图(the date directory views)
user_tab_comments;表注释:有三个字段TABLE_NAME,TABLE_TPYE,COMMENTS
user_col_comments;表字段注释:有三个字段TABLE_NAME,CLUMN_NAME,COMMENTS
2. 访问其他用户的注释信息要查询的数据字典视图(the date directory views)
all_tab_comments;表注释:有四个字段OWNER,TABLE_NAME,TABLE_TPYE,COMMENTS
all_col_comments;表字段注释:有四个字段OWNER,TABLE_NAME,CLUMN_NAME,COMMENTS
3. DBA权限用户可访问所有用户的注释信息要查询的数据字典视图(the date directory views):
dba_tab_comments;表注释:有四个字段OWNER,TABLE_NAME,TABLE_TPYE,COMMENTS
dba_col_comments;表字段注释:有四个字段OWNER,TABLE_NAME,CLUMN_NAME,COMMENTS
用法如下:
1.查看表的说明
SQL> select * from user_tab_comments where TABLE_NAME='EMPLOYEES';
2.查看表中列的说明
SQL> select * from user_col_comments where TABLE_NAME='EMPLOYEES';
3.删除表级说明,也就是将其置为空
SQL> comment on table EMPLOYEES is '';
4.删除列级说明,也是将其置为空
SQL> comment on column EMPLOYEES.salary is '';