在Oracle下实现主键自增(触发器)
-- Create table 创建表
create table T_USERS
(
userid NUMBER not null,
username VARCHAR2(20)
)
-- Create sequence 创建序列
create sequence T_USER_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 21
increment by 1
cache 20;
最大值和最小值可以不设置,会自动填充
--create trigger 创建触发器
create or replace trigger T_User_Trig
before insert on t_users
for each row
begin
select T_USER_SEQ.nextval into :new.USERID from dual;
end;