oracle添加自增字段

-- Create table

create table T_IMPORTDATE_LOG
(
  PK         INTEGER not null,
  EXECDATE   DATE,
  DATADATE   DATE,
  BRANCHFLAG CHAR(3),
  REMARKS    VARCHAR2(200)
)
tablespace REPORT
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 16
    minextents 1
    maxextents unlimited
  );
-- Add comments to the columns
comment on column T_IMPORTDATE_LOG.EXECDATE
  is '执行时间';
comment on column T_IMPORTDATE_LOG.DATADATE
  is '数据日期';
comment on column T_IMPORTDATE_LOG.BRANCHFLAG
  is '公司标识';
comment on column T_IMPORTDATE_LOG.REMARKS
  is '备注';

alter table T_IMPORTDATE_LOG
  add primary key (PK)
  using index
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );


create sequence T_importdate_LOG_SEQ
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 10
order;


create or replace trigger tri_inportdate_log
before insert on T_IMPORTDATE_LOG
for each row
begin
select T_importdate_LOG_SEQ.nextval into :new.pk from dual;
end tri_importdate_log;


--T_IMPORTDATE_LOG表的PK列,就是自增长的了

posted @ 2009-06-30 13:05  左少白  阅读(528)  评论(0编辑  收藏  举报