### 25.2.4 Stored Procedures, Functions, Triggers, and LAST\_INSERT\_ID()

[]()[]()[]()[]()

 Within the body of a stored routine (procedure or function) or a trigger, the value of [`LAST_INSERT_ID()`](information-functions.html#function_last-insert-id) changes the same way as for statements executed outside the body of these kinds of objects (see [Section 12.16, “Information Functions”](information-functions.html)). The effect of a stored routine or trigger upon the value of [`LAST_INSERT_ID()`](information-functions.html#function_last-insert-id) that is seen by following statements depends on the kind of routine:

* If a stored procedure executes statements that change the value of [`LAST_INSERT_ID()`](information-functions.html#function_last-insert-id), the changed value is seen by statements that follow the procedure call.

* For stored functions and triggers that change the value, the value is restored when the function or trigger ends, so following statements do not see a changed value.

