首頁  >  文章  >  資料庫  >  如何使Oracle触发器主键自动增长

如何使Oracle触发器主键自动增长

WBOY
WBOY原創
2016-06-07 17:45:42758瀏覽

1,创建sequence:

  create sequence SEQ_SM_USER

  minvalue 1

  maxvalue 999999999999999999999999999

  start with 1

  increment by 1

  cache 20;

  2,创建触发器:

  create or replace trigger tg_sm_user

  before insert on sm_user

  referencing old as oldval

  new as newval

  for each row

  begin

  select seq_sm_user.nextval into :newval.pk_user from dual;

  end;

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn