Home » RDBMS Server » Server Administration » Autoincrement Identity Field
Autoincrement Identity Field [message #371551] Mon, 06 November 2000 16:19 Go to next message
Marco Bernal
Messages: 1
Registered: November 2000
Junior Member
PLEASE HELP ME!!!
What can I do to set a column to primary key, numeric
and that every time I insert to that table the primary
key field increments it self by 1 ?
Re: Autoincrement Identity Field-try this [message #371552 is a reply to message #371551] Mon, 06 November 2000 17:36 Go to previous message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
create sequence my_tab_seq start with 1;

CREATE OR REPLACE TRIGGER my_tab_bins
BEFORE INSERT
ON my_tab
FOR EACH ROW
BEGIN
SELECT my_tab_seq.nextval
INTO :new.pk_col
FROM dual; -- dummy Oracle table!
END my_tab_bins;
/

you could also do it without a trigger like this (more efficient):
insert into my_tab values(my_tab_seq.nextval, 123, 'xyz', sysdate );
Previous Topic: Conditional Select from PL/SQL tables.
Next Topic: Update
Goto Forum:
  


Current Time: Fri May 03 16:57:19 CDT 2024