Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6923806
  • 博文数量: 700
  • 博客积分: 10821
  • 博客等级: 上将
  • 技术积分: 12011
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-02 10:41
个人简介

大数据、ML、AI、云计算openstack、Linux、SpringCloud。

文章分类

全部博文(700)

分类: Oracle

2013-10-10 14:23:44

comment on给表或字段加以说明
1:可以在建表时追加 create table tabAA (...)/comment on table table_name is ‘aaaa’/
2:查看:表名()user_tab_comments,user_col_comments


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    

阅读(4245) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~