Nethence Documentation Lab Webmail Your IP BBDock  

Those documents are obsolete, please use the Nethence Documentation instead.


Oracle auto increment
. oraenv
Create table with an autoincrement id column,
create table table1 (id number, col2 varchar2(255));
create sequence table1_seq
    start with 1 increment by 1 nomaxvalue;
create trigger table1_trigger
    before insert on table1 for each row begin
      select table1_seq.nextval into from dual;
check the sequence and trigger is configured,
select sequence_name from user_sequences;
select trigger_name from user_triggers;
note. to delete sequences and triggers,
#drop sequence test_seq;
#drop trigger test_trigger;
note. enable/disable a trigger,
#alter trigger test_trigger disable;
#alter trigger test_trigger enable;
note. instead of the trigger, it's also possible to autoincrement from the INSERT statement,
#insert into test values(test_seq.nextval, 'voila!');
Insert a row in that table (first column is autoimcremented) and commit,
insert into table1 values(NULL, 'lala');
insert into table1 values(NULL, 'lili');
check everything is there,
select * from table1;
Delete a row,
delete from table1 where id=2;
delete all table's content,
--truncate table1;
delete table1;
note. same as "delete from table1;"
drop a table,
drop table table1;
Other queries,
select table_name from user_tables;
insert into table1 values(NULL, 'lala');
insert into table1 values(NULL, 'lili');
insert into table1 values(NULL, 'lolo');

Last update: Apr 09, 2010