1. 程式人生 > >oracle建立表增加欄位sql指令碼

oracle建立表增加欄位sql指令碼

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
  );