主键递增用 IDENTITY 例如:CREATE TABLE dbo.Tmp_t_t01 ( id int NOT NULL IDENTITY (1, 1), id2 int NULL ) ON [PRIMARY]
--1.先创建序列 scott@YPCOST> create sequence orderNo_seq start with 100 increment by 1 maxvalue 999;序列已创建。scott@YPCOST> create table test(id number,name varchar2(20));表已创建。--2、再加触发器 scott@YPCOST> ed 已写入 file afiedt.bufcreate or replace trigger insert_tri before insert on test for each row declare begin select orderNo_seq.nextval into :new.id from dual; end; scott@YPCOST> /触发器已创建scott@YPCOST> insert into test(name) values('tom');已创建 1 行。scott@YPCOST> commit;提交完成。scott@YPCOST> select * from test;ID NAME -------------------- -------------------- 100 tom
例如:CREATE TABLE dbo.Tmp_t_t01
(
id int NOT NULL IDENTITY (1, 1),
id2 int NULL
) ON [PRIMARY]
--1.先创建序列
scott@YPCOST> create sequence orderNo_seq start with 100 increment by 1 maxvalue 999;序列已创建。scott@YPCOST> create table test(id number,name varchar2(20));表已创建。--2、再加触发器
scott@YPCOST> ed
已写入 file afiedt.bufcreate or replace trigger insert_tri
before insert on test
for each row
declare
begin
select orderNo_seq.nextval into :new.id from dual;
end;
scott@YPCOST> /触发器已创建scott@YPCOST> insert into test(name) values('tom');已创建 1 行。scott@YPCOST> commit;提交完成。scott@YPCOST> select * from test;ID NAME
-------------------- --------------------
100 tom