I have created a routine which inserts a record in one table, and after that it searches for that id (with a select statement) and updates another table's field with that id.Is this possible? It's one routine so my question is if the statements are executed in a sequential order?
Thanks in advance
You do not need to search for the id. You can use
LAST_INSERT_ID()
to get the id of the last inserted row.INSERT INTO tablename (<columns>) VALUES (<columnvalues>);
SELECT LAST_INSERT_ID() INTO somevariable;
Then you can write your
UPDATE
statement.UPDATE sometable SET sometable.col = somevariable WHERE sometable.something = @something
Statements in a routine are executed in the order they are written.