oracle的自增长可以通过SEQUENCE和TRIGGER来实现.
若想要实现某字段在所有表里统一自增
例如为了实现A和B表中的id列统一自增,也就是当A表中..id值为3,紧接着在B表中插入一条记录.系统自动给B中id赋值为4..再插入...赋值为5...此时若接着向A中插入记录..系统将自动给A中的新插记录的id赋值为6...
只需要将A和B两个表在insert上的触发器和同一个SEQUENCE关联即可.
CREATE OR REPLACE TRIGGER t_xxxA_trigger BEFORE INSERT ON t_xxxA FOR EACH ROW when (new.id is null) begin select t_id_seq.nextval into :new.id from dual; end;
CREATE OR REPLACE TRIGGER t_xxxB_trigger BEFORE INSERT ON t_xxxB FOR EACH ROW when (new.id is null) begin select t_id_seq.nextval into :new.id from dual; end;
|
阅读(1538) | 评论(1) | 转发(0) |