oracle 创建自动增加主键的表
//创建表
create table t (pk number primary key,name varchar2(20));
//创建序列
create sequence t_seq
increment by 1
start with 1 maxvalue 999999999;
//创建触发器
create trigger t_trigger before insert on t for each row
begin
select t_seq.nextval into :new.pk from dual; //or ( new.pk=t_seq.nextval)
end;
//插入记录
insert into t(name) values('aa');
create table t (pk number primary key,name varchar2(20));
//创建序列
create sequence t_seq
increment by 1
start with 1 maxvalue 999999999;
//创建触发器
create trigger t_trigger before insert on t for each row
begin
select t_seq.nextval into :new.pk from dual; //or ( new.pk=t_seq.nextval)
end;
//插入记录
insert into t(name) values('aa');