# Stored Routine Limitations

The following SQL statements are not permitted inside any [stored routines](https://mariadb.com/docs/server/server-usage/stored-routines) ([stored functions](https://mariadb.com/docs/server/server-usage/stored-routines/stored-functions), [stored procedures](https://mariadb.com/docs/server/server-usage/stored-routines/stored-procedures), [events](https://mariadb.com/docs/server/server-usage/triggers-events/event-scheduler/events) or [triggers](https://mariadb.com/docs/server/server-usage/triggers-events/triggers)).

* [ALTER VIEW](https://mariadb.com/docs/server/server-usage/views/alter-view); you can use [CREATE OR REPLACE VIEW](https://mariadb.com/docs/server/server-usage/views/create-view) instead.
* [LOAD DATA](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/inserting-loading-data/load-data-into-tables-or-index/load-data-infile) and [LOAD TABLE](https://mariadb.com/docs/server/ha-and-performance/standard-replication/obsolete-replication-information/load-table-from-master-removed).
* [CHANGE MASTER TO](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/replication-statements/change-master-to)
* [INSERT DELAYED](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/inserting-loading-data/insert-delayed) is permitted, but the statement is handled as a regular [INSERT](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/inserting-loading-data/insert).
* [LOCK TABLES](https://mariadb.com/docs/server/reference/sql-statements/transactions/lock-tables) and [UNLOCK TABLES](https://mariadb.com/docs/server/reference/sql-statements/transactions/lock-tables).
* References to [local variables](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/declare-variable) within prepared statements inside a stored routine (use [user-defined variables](https://mariadb.com/docs/server/reference/sql-structure/sql-language-structure/user-defined-variables) instead).
* [BEGIN (WORK)](https://mariadb.com/docs/server/reference/sql-statements/transactions/start-transaction) is treated as the beginning of a [BEGIN END](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/begin-end) block, not a transaction, so [START TRANSACTION](https://mariadb.com/docs/server/reference/sql-statements/transactions/start-transaction) needs to be used instead.
* The number of permitted recursive calls is limited to [max\_sp\_recursion\_depth](https://mariadb.com/docs/server/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](https://mariadb.com/docs/server/reference/sql-statements/prepared-statements/prepare-statement#permitted-statements) for a list of statements that can be used. [SIGNAL](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/signal), [RESIGNAL](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/resignal) and [GET DIAGNOSTICS](https://mariadb.com/docs/server/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](https://mariadb.com/docs/server/server-usage/stored-routines/stored-functions/stored-function-limitations)
* [Trigger Limitations](https://mariadb.com/docs/server/server-usage/triggers-events/triggers/trigger-limitations)
* [Event Limitations](https://mariadb.com/docs/server/server-usage/triggers-events/event-scheduler/event-limitations)

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/server-usage/stored-routines/stored-routine-limitations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
