home screen

Search



Number Of Result : 0

Result :


Sunday, August 9, 2009

create auto increment columns in oracle

- the first step is to create you table, including the field you plan to use as a unique auto-incremented identifier :

- Create My_Test Table

create table My_Test (
id number,
my_test data varchar2(255)
);



- secondly you can create a sequence for that table - a sequence is a specific oracle command that handles increments. -

create sequence test_seq
start with 1
increment by 1
nomaxvalue;


- an finally you can instanciate a trigger for that table forcing auto allocation of the designated column before the insert is performed :

create trigger test_trigger
before insert on My_Test
for each row
begin
select test_seq.nextval into :new.id from dual;
end;



No comments: