不是因为有些事情难以做到,我们才失去自信,而是我们失去了自信,这些事情才难以做到!

Oracle自增ID的解决办法

上一篇 / 下一篇  2008-11-05 15:43:47 / 个人分类:开发技术

首先创建一个索引,然后创建一个触发器
tY7_7Gw9]051Testing软件测试网.q9Op)Wv3g Y
索引的名字: SEQ_tproduct
+F3B5PPwrfg0触发器的名字: addid
,m2WQU!]9g@ O0表名:tproduct
YZ4H~1J6[.u0自增列名:pid 51Testing软件测试网P.hxk%?
51Testing软件测试网sjoJx"xdo
create sequence SEQ_tproduct                                             51Testing软件测试网%_4nGJ~KJ:a9D$?
minvalue 1
;Cdm4A)M[8\&^]0start with 1 51Testing软件测试网 P,F$P Sh)Kd]
increment by 1 51Testing软件测试网1I_*VY7UIG `
nocache;

%p$[R$v!R'uFE051Testing软件测试网t[6B4gP5XF9ZL

Y$yp2^GD}x0create or replace trigger addid
S*az-g g U!{.|0before insert on tproduct 51Testing软件测试网 r[0uu0Dj'V&Ws
for each row 51Testing软件测试网lb!n!E^q
begin
bv!`/HYO6L+R0select SEQ_tproduct.nextval into :new.pid from dual; 51Testing软件测试网L!i$?wC{o+I
end;

TAG: 学习笔记

 

评分:0

我来说两句

Open Toolbar