Oracle实现主键自增


建序列:
  1. create sequence SQ_PUBLIC  
  2. minvalue 1  
  3. maxvalue 999999  
  4. start with 1  
  5. increment by 1;  

建触发器:

  1. SQL> create or replace trigger exam_tri  
  2.   2    before insert on t_example  
  3.   3    for each row  
  4.   4  begin  
  5.   5    select sq_public.nextval into:new.id from dual;  
  6.   6  end dept_tri;  
  7.   7  /  

如果不用触发器的话,插入数据时,直接在ID字段插入SQ_PUBLIC.NEXTVAL。

相关内容