Oracle建立序列-触发器设置主键自增

建立序列.创建索引sql

2.建立触发器:找到要设置自增的表,右键编辑后,切换至触发器,新建触发器如图:
须要设置触发器的名字及触发方式:编辑器

3.确认后会出现sql编辑器:spa

select pid.nextval into :new.pid from dual;
第一个pid就是以前序列的名称,改为本身的便可。 第二个pid就是表里须要自增的字段。

 二:使用语句建立code

1:建立索引blog

create sequence SEQ_USERINFO---索引名称
minvalue 1 –最小值
nomaxvalue –不设置最大值
start with 1 –从1开始计数
increment by 1 –每次加1个
nocycle –一直累加,不循环
nocache; –不建缓冲区
索引

2:建立触发器rem

create or replace trigger tri_person(自定义触发器名称)
before insert
on person----表名
for each row
begin
  select seq_person(以前定义的序列名).nextval into :new.pid(须要自增的字段) from dual; end;
例如:
it

create or replace trigger pid
  before insert
  on PROCESS_CHECK
  for each row
declare
  -- local variables here
begin
  select PROCESS_CHECK_SEQUENCE.nextval into :new.ID_ from dual;
end ;
class

相关文章
相关标签/搜索