[导入]在ASP.NET+ORACLE添加数据记录并让ID自动增量
在ASP.NET+ORACLE添加数据记录并让ID自动增量需要在ORACLE中设序列和触发器即可,切记不是索引,ASP.NET中不管ID,具体如下:
1、建立序列:
CREATE SEQUENCE seq_emergency_id
NOCYCLE
MAXVALUE 9999999999
START WITH 2;
2、建立触发器:
CREATE OR REPLACE TRIGGER set_emergency_id
BEFORE INSERT ON "EMERGENCY"
FOR EACH ROW
DECLARE
next_emergency_id NUMBER;
BEGIN
--Get the next emergency id from the sequence
SELECT seq_emergency_id.NEXTVAL
INTO next_emergency_id
FROM dual;
--use the sequence number as the primary key
--for the record being inserted
:new.id := next_emergency_id;
END;
如果在企业管理器中创建,在触发器说明中填:
DECLARE
next_emergencycb_id NUMBER;
BEGIN
--Get the next id number from the sequence
SELECT seq_emergencycb_id.NEXTVAL
INTO next_emergencycb_id
FROM dual;
--use the sequence number as the primary key
--for the record being inserted
:new.id := next_emergencycb_id;
END;
文章来源:http://dotnet.mblogger.cn/zeusvenus/posts/7258.aspx