这几天搞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;
本文介绍如何在Oracle数据库中为表的主键设置自动增长功能。通过创建序列和触发器的方法实现每插入一条新记录时,主键字段自动递增。
1876

被折叠的 条评论
为什么被折叠?



