- A stored procedure is a set of SQL statements saved under a name and stored in the database. You can execute it repeatedly with different inputs.
- A function (UDF) is similar but must return a single value and is typically used in SELECT statements.
They improve modularity, code reuse, and performance by reducing network traffic and centralizing logic in the database.
Limitations of MySQL Functions
- Cannot modify database (no INSERT, UPDATE, DELETE).
- Cannot call stored procedures.
- Limited to deterministic logic.
- No transaction control allowed.