Re: LAST_INSERT_ID() AND UPDATE STATEMENTS
last_insert_id() has always been available after an INSERT to a table with auto_increment, no matter which version. Since UPDATE does not change the auto_increment value.
When you perform an UPDATE statement, you already know exactly which rows are updated since you provide the condition to choose the row using the WHERE clause in the update statement. There is no need to know the auto_increment value at all, use the same condition in a select to find the row. Of course, without transaction, the update and select may not get the same row if someone changes it in between your 2 statement.
A trick with user variable, if the update changes only 1 row, you can use this.
UPDATE table SET id=(@tempid:=id) , .... LIMIT 1;
SELECT @tempid;
This will not be affected by changes from other connections.
Subject
Views
Written By
Posted
17171
May 26, 2007 03:06AM
4761
May 27, 2007 03:03AM
4340
May 27, 2007 06:34AM
Re: LAST_INSERT_ID() AND UPDATE STATEMENTS
5769
May 27, 2007 04:38PM
3687
May 28, 2007 12:31AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.