Jon-G blogs for Net-Entwicklung.de

08.05.2009

Autoincrement in Oracle DB mittels Sequence und Trigger

Filed under: Databases — Schlagwörter: , — Jonathan Gilbert @ 15:50

CREATE SEQUENCE [tablename]_SEQ

START WITH 1
MAXVALUE 9999999999
MINVALUE 1
NOCYCLE
CACHE 20
NOORDER;

CREATE OR REPLACE TRIGGER [tablename]_trigger

BEFORE INSERT ON [tablename]

FOR EACH ROW

BEGIN

SELECT [tablename]_SEQ.NEXTVAL INTO :NEW.[primarykey] FROM DUAL;

END;

Bloggen auf WordPress.com.