Query with an Insert query

sevensins

Disciple
I am using MySQL as the database.
I have a table in which the ID Field is the primary key with an auto increment option.
Now whenever a new row is inserted the ID field populates the next number aka MAX+1.

My question is, how do I make the insert statement return me back the ID field value whenever a new row is inserted ?

The insert is just like any normal insert statement and the ID Field gets auto generated since its set to auto increment.

Also it should be taken into consideration that multiple users would be doing the insert and would expect the corresponding ID field to be returned. No mismatch.

Awaiting replies
 
For MySql you can use "mysql_insert_id()" , it will give the last generated auto-increment id and you need not worry about multiple user accessing the site as this function is session specific.

You can also use "LAST_INSERT_ID()", but the problem with that is .. if you are giving 5 insert statements together.. it will give you the value of the first statement that was inserted.

For MS products you can use @@IDENTITY for retrieving the last generated id.
Happy coding :)
 
ultra vires said:
For MySql you can use "mysql_insert_id()" , it will give the last generated auto-increment id and you need not worry about multiple user accessing the site as this function is session specific.

Thanks and I think that you saved my day..:hap2: repped..
 
Back
Top