oracle主键自增

1、指定主键,如id,后面new.id中id就是主键,如果主键为userid,那么就得改为new.userid 

2、创建序列

create  sequence xx_CALENDAR_ID 
minvalue 1
nomaxvalue 
increment by 1 
start with 1
nocache;

3、创建触发器,触发器中的xx_CALENDAR_ID.nextval为上面创建的序列名称,on xx_CALENDAR为要操作的表名

create or replace trigger xx_CALENDAR_TG_INSERTID
before insert on xx_CALENDAR  
 for each row      
begin    
  select  xx_CALENDAR_ID.nextval into :new.id from dual; 
end;

参考:https://blog.csdn.net/bronzehammer/article/details/80755376

posted @ 2021-10-28 15:13  关键步就几步  阅读(282)  评论(0编辑  收藏  举报