i have a little problem about how to create an auto-increment process. i'm using an oracle and all the table and data is already exist in my database. I have seen a few example from internet and it is like this.

table users {
id int(13) not null auto_increment,
name varchar( 45 ) not null default '',
email varchar( 55 ) not null default '',
website varchar( 100 ) not null default '',
primary key( id )

create sequence test_seq
start with 1
increment by 1

create trigger test_trigger
before insert on barkod
for each row
Select test_seq.nextval into:new.barkod from dual;

should i follow this example even all the tables and data are already exist in my database?? hope anyone in here can show step by step how to create it.
~really need help her...
~thank you...

11 Years
Discussion Span
Last Post by sillyboy

It's definately Oracle. The first statement there is not actually valid, it's just describing the existing table for you The next one creates an incrementing sequence, however I would never use a trigger to implement it as you can't find out what the value of the sequence is without requerying the table. Then you have to rely on the line being easily identifiable without having it's primary key, pretty ugly. Create the sequence and in your business logic when you insert select the nextval and save it to a variable, then insert the line with that variable value as the key field. Then you know what line in the database you should be looking at.


sorry dear the statment auto_increment is not valid in oracle , so it is not it oracle but in postgre sql .Restall u can aany way define in oracle.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.