oracle 创建自动增加主键的表
create table t (pk number primary key,name varchar2(20));
create sequence t_seq ;
create trigger t_trigger before insert on t for each row
begin
select seq.nextval into :new.pk from dual;
end;
/
测试:select * from t;
未选定行
create sequence t_seq ;
create trigger t_trigger before insert on t for each row
begin
select seq.nextval into :new.pk from dual;
end;
/
测试:select * from t;
未选定行
SQL> insert into t(name) values ('aa');
已创建 1 行。
SQL> select * from t;
PK NAME
---------- ----------------------------------------
1 aa
SQL> insert into t(name) values ('bb');
已创建 1 行。
SQL> select * from t;
PK NAME
---------- ----------------------------------------
1 aa
2 bb
posted on 2008-04-16 09:47 johnnyking39 阅读(779) 评论(0) 编辑 收藏 举报