hello...
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
nomaxvalue;

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

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...

Recommended Answers

All 4 Replies

I don't think that is in ORACLE.

R u sure.

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.

Just get rid of "auto_increment".
I think it'll work with int(13), if not, just use NUMBER.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.