配合序列 和 触发器完成
userid number(10) primary key, /*主键,自动增加*/
username varchar2(20)
);
2.建序列
CREATE SEQUENCE TestIncrease_Sequence
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
CACHE 10;
3.建触发器
CREATE TRIGGER Test_Increase BEFORE
insert ON Test_Increase FOR EACH ROW
begin
select TestIncrease_Sequence.nextval into:New.userid from dual;
insert into Test_Increase(Username) values('test');
1.建表
userid number(10) primary key, /*主键,自动增加*/
username varchar2(20)
);
2.建序列
CREATE SEQUENCE TestIncrease_Sequence
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
CACHE 10;
3.建触发器
CREATE TRIGGER Test_Increase BEFORE
insert ON Test_Increase FOR EACH ROW
begin
select TestIncrease_Sequence.nextval into:New.userid from dual;
end;
insert into Test_Increase(Username) values('test');
commit;
select * from Test_Increase;