•Within all stored programs (stored procedures and functions, triggers, and events), the parser treats BEGIN [WORK]  as the beginning of a BEGIN ... END  block. To begin a transaction in this context, use START TRANSACTION  instead. 

## Restrictions for Stored Functions 

The following additional statements or operations are not permitted within stored functions. They are permitted within stored procedures, except stored procedures that are invoked from within a stored function or trigger. For example, if you use FLUSH  in a stored procedure, that stored procedure cannot be called from a stored function or trigger. 

•Statements that perform explicit or implicit commit or rollback. Support for these statements is not required by the SQL standard, which states that each DBMS vendor may decide whether to permit them. 

•Statements that return a result set. This includes SELECT  statements that do not have an INTO var_list  clause and other statements such as SHOW , EXPLAIN , and CHECK TABLE . A function can process a result set either with SELECT ... INTO var_list  or by using a cursor and FETCH statements. See Section 13.2.10.1, “SELECT ... INTO Statement” , and Section 13.6.6, “Cursors” . 

• FLUSH  statements. 

•Stored functions cannot be used recursively. 

•A stored function or trigger cannot modify a table that is already being used (for reading or writing) by the statement that invoked the function or trigger. 

•If you refer to a temporary table multiple times in a stored function under different aliases, a Can’t reopen table: ’ tbl_name ’  error occurs, even if the references occur in different statements within the function. 

• HANDLER ... READ  statements that invoke stored functions can cause replication errors and are disallowed. 

## Restrictions for Triggers 

For triggers, the following additional restrictions apply: 

•Triggers are not activated by foreign key actions. 

•When using row-based replication, triggers on the replica are not activated by statements originating on the source. The triggers on the replica are activated when using statement-based replication. For more information, see Section 17.5.1.36, “Replication and Triggers” . 

•The RETURN  statement is not permitted in triggers, which cannot return a value. To exit a trigger immediately, use the LEAVE  statement. 

•Triggers are not permitted on tables in the mysql  database. Nor are they permitted on INFORMATION_SCHEMA  or performance_schema  tables. Those tables are actually views and triggers are not permitted on views. 

•The trigger cache does not detect when metadata of the underlying objects has changed. If a trigger uses a table and the table has changed since the trigger was loaded into the cache, the trigger operates using the outdated metadata. 

## Name Conflicts within Stored Routines 

The same identifier might be used for a routine parameter, a local variable, and a table column. Also, the same local variable name can be used in nested blocks. For example: 

