# Stored Routine Limitations

The following SQL statements are not permitted inside any [stored routines]() ([stored functions](stored-functions), [stored procedures](stored-procedures), [events](../triggers-events/event-scheduler/events) or [triggers](../triggers-events/triggers)).

* [ALTER VIEW](../views/alter-view); you can use [CREATE OR REPLACE VIEW](../views/create-view) instead.
* [LOAD DATA](../../reference/sql-statements/data-manipulation/inserting-loading-data/load-data-into-tables-or-index/load-data-infile) and [LOAD TABLE](../../ha-and-performance/standard-replication/obsolete-replication-information/load-table-from-master-removed).
* [CHANGE MASTER TO](../../reference/sql-statements/administrative-sql-statements/replication-statements/change-master-to)
* [INSERT DELAYED](../../reference/sql-statements/data-manipulation/inserting-loading-data/insert-delayed) is permitted, but the statement is handled as a regular [INSERT](../../reference/sql-statements/data-manipulation/inserting-loading-data/insert).
* [LOCK TABLES](../../reference/sql-statements/transactions/lock-tables) and [UNLOCK TABLES](../../reference/sql-statements/transactions/lock-tables).
* References to [local variables](../../reference/sql-statements/programmatic-compound-statements/declare-variable) within prepared statements inside a stored routine (use [user-defined variables](../../reference/sql-structure/sql-language-structure/user-defined-variables) instead).
* [BEGIN (WORK)](../../reference/sql-statements/transactions/start-transaction) is treated as the beginning of a [BEGIN END](../../reference/sql-statements/programmatic-compound-statements/begin-end) block, not a transaction, so [START TRANSACTION](../../reference/sql-statements/transactions/start-transaction) needs to be used instead.
* The number of permitted recursive calls is limited to [max\_sp\_recursion\_depth](../../../server-management/variables-and-modes/server-system-variables#max_sp_recursion_depth). If this variable is 0 (default), recursivity is disabled. The limit does not apply to stored functions.
* Most statements that are not permitted in prepared statements are not permitted in stored programs. See [Prepare Statement:Permitted statements](../../../reference/sql-statements/prepared-statements/prepare-statement#permitted-statements) for a list of statements that can be used. [SIGNAL](../../reference/sql-statements/programmatic-compound-statements/signal), [RESIGNAL](../../reference/sql-statements/programmatic-compound-statements/resignal) and [GET DIAGNOSTICS](../../reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-diagnostics/get-diagnostics) are exceptions, and may be used in stored routines.

There are also further limitations specific to the kind of stored routine.

Note that, if a stored program calls another stored program, the latter will inherit the caller's limitations. So, for example, if a stored procedure is called by a stored function, that stored procedure will not be able to produce a result set, because stored functions can't do this.

## See Also

* [Stored Function Limitations](stored-functions/stored-function-limitations)
* [Trigger Limitations](../triggers-events/triggers/trigger-limitations)
* [Event Limitations](../triggers-events/event-scheduler/event-limitations)

<sub>_This page is licensed: CC BY-SA / Gnu FDL_</sub>

{% @marketo/form formId="4316" %}
