1、创建表
create table note( id number(20) NOT NULL primary key,/*主键,自动增加*/ name varchar2(20));
2、创建自动增长序列
Create Sequence addAuto_Sequence
Increment by 1 -- 每次加几个
start with 1 -- 从1开始计数
nomaxvalue -- 不设置最大值,设置最大值:
maxvalue 9999 nocycle -- 一直累加,不循环
cache 10;
3、创建触发器
Create trigger addAuto before
insert on note(表名) for each row /*对每一行都检测是否触发*/
begin
select addAuto_Sequence.nextval into:New.id from dual;
end;