【Oracle】添加注释(COMMENT ON)

在数据库中创建表以后,有时需要添加表或者列的描述信息,也就是注释。这样当后来者查看表结构时,就可以清楚的知道表或者字段的含义。


1. 语法
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' ;


2. 添加注释
(1)添加表级注释
SQL> COMMENT ON TABLE EMP IS 'EMPLOYEES';


(2)添加列级注释
SQL> COMMENT ON COLUMN EMP.ENAME IS 'EMPLOYEES NAME';


3. 查看已添加注释
(1)查看表级注释
SQL> SELECT * FROM USER_TAB_COMMENTS WHERE TABLE_NAME='EMP';

(2)查看列级注释
SQL> SELECT * FROM USER_COL_COMMENTS WHERE COLUMN_NAME='ENAME' AND COMMENTS IS NOT NULL;

4. 删除注释(即,添加空注释)
SQL> COMMENT ON TABLE EMP IS '';

SQL> COMMENT ON COLUMN EMP.ENAME IS '';

SQL> SELECT * FROM USER_TAB_COMMENTS WHERE TABLE_NAME='EMP';

SQL> SELECT * FROM USER_COL_COMMENTS WHERE COLUMN_NAME='ENAME' AND TABLE_NAME='EMP';




你可能感兴趣的:(Oracle)