Oracle建表主键自动增长.
–建表
create table PLAN_CONTRACT(id number not null primary key,
PLAN_ID number,
CONTRACT_ID number);
– 建立序列:
– Create sequence
create sequence PLAN_CONTRACT_SEQUENCE
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;
– 建立触发器
create trigger “PLAN_CONTRACT_trigger” before
insert on PLAN_CONTRACT for each row when(new.id is null)
begin
select PLAN_CONTRACT_sequence.nextval into:new.id from dual;
end;