oracle主键自增长
这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下:
create table simon_example
(
id number(4) not null primary key,
name varchar2(25)
)
-- 建立序列:
-- Create sequence
create sequence SIMON_SEQUENCE
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;
-- 建立触发器
create trigger "simon_trigger" before
insert on simon_example for each row when(new.id is null)
begin
select simon_sequence.nextval into:new.id from dual;
end;
posted on 2011-07-24 21:03 BarneyZhang 阅读(269) 评论(0) 编辑 收藏 举报