oracle comment on的用法
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
下面我展示一下项目开发中的实例来做参考
-- Create table
create table F_S_WASH_TASK
(
task_id NUMBER(16) not null,
task_no VARCHAR2(16) not null,
equip_categ VARCHAR2(8),
task_status VARCHAR2(8) not null,
start_date DATE not null,
end_date DATE,
task_num NUMBER(15),
org_no VARCHAR2(16) not null,
creator_no VARCHAR2(16),
create_date DATE,
exec_org_no VARCHAR2(16),
team_no VARCHAR2(16),
executor_no VARCHAR2(16),
parent_task_id NUMBER,
priority VARCHAR2(8) not null,
remark VARCHAR2(32),
finish_remark VARCHAR2(256),
wiring_mode VARCHAR2(8),
finished_date DATE,
real_start_date DATE
)
tablespace MPAC_A
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64
next 1
minextents 1
maxextents unlimited
);
-- Add comments to the table
comment on table F_S_WASH_TASK
is '清洁分选任务表';
-- Add comments to the columns
comment on column F_S_WASH_TASK.task_id
is '唯一标识';
comment on column F_S_WASH_TASK.task_no
is '清洁分选任务编';
comment on column F_S_WASH_TASK.equip_categ
is '设备类别,参见计量标准代码:设备类别VW_EQUIP_CATEG';
comment on column F_S_WASH_TASK.task_status
is '任务状态,01初始、02待分配、03已分配、04执行中、05执行完成、06已完成';
comment on column F_S_WASH_TASK.start_date
is '任务开始时间';
comment on column F_S_WASH_TASK.end_date
is '任务结束时间';
comment on column F_S_WASH_TASK.task_num
is '任务数量';
comment on column F_S_WASH_TASK.org_no
is '创建单位编号';
comment on column F_S_WASH_TASK.creator_no
is '创建人';
comment on column F_S_WASH_TASK.create_date
is '创建时间';
comment on column F_S_WASH_TASK.exec_org_no
is '执行单位';
comment on column F_S_WASH_TASK.team_no
is '执行班组';
comment on column F_S_WASH_TASK.executor_no
is '执行人';
comment on column F_S_WASH_TASK.parent_task_id
is '父任务标识';
comment on column F_S_WASH_TASK.priority
is '任务优先级 01一般 02 重要 03紧急';
comment on column F_S_WASH_TASK.remark
is '备注';
comment on column F_S_WASH_TASK.finish_remark
is '任务完成备注';
comment on column F_S_WASH_TASK.wiring_mode
is '接线方式';
comment on column F_S_WASH_TASK.finished_date
is '任务完成日期';
comment on column F_S_WASH_TASK.real_start_date
is '任务实际开始时间';
-- Create/Recreate primary, unique and foreign key constraints
alter table F_S_WASH_TASK
add constraint PK_F_S_WASH_TASK primary key (TASK_ID)
using index
tablespace MPAC_A
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);