读书人

oracle触发器写一个主键从增

发布时间: 2012-09-10 11:02:32 作者: rapoo

oracle触发器写一个主键自增
1.首先创建一个序列:

create sequence s_user_info //user_info是表名       increment by 1       start with 1 maxvalue 99999999       nocycle       nocache//以下是查看数据库里面的序列select sequence_name from user_sequences

2.然后创建触发器
create or replace trigger tri_user_info  before insert on user_info  for each rowdeclare  -- local variables here  nextid number;begin    select s_user_info.nextval//此为上面创建的序列    into nextid    from sys.dual;    :new.ID:=nextid;//ID为主键end tri_user_info;

读书人网 >其他数据库

热点推荐