---
# System prepended metadata

title: Stored Routines and Triggers

---

# Stored Procedures and Triggers
## Agenda

Understanding Stored Routines
- Benefits and Downsides of Stored Routines

Creating and Executing Stored Procedures
- Syntax for Creating a Stored Procedure
- Initial Stored Procedure example
- Stored Procedure CharacteristicsProgrammatic Maintenance
- Defining a Stored Procedure with Characteristics
- Control Structures in Stored Procedures and Functions
- Exception Handler
- Variables
- Cursors
- Permissions

Creating and Using Stored Functions
- Syntax for Creating a Stored Function
- Defining a Stored Function

Using Stored Routines in Queries

Understanding Triggers
- Definition, functionalities and syntax
- Triggering Events and Actions in SQL: some good practices & hints

Creating and Using Triggers
- Data Validity
- Data Change Auditing
- Data Integrity
- Programmatic Maintenance
- Statement Level aggregation

Managing Triggers
- Enabling / disabling triggers
- Dropping triggers
- When Not To Use Triggers

## References

[MySQL Documentation on Stored Routines](https://dev.mysql.com/doc/refman/9.2/en/stored-routines.html) (Procedures & Functions)
[MySQL Documentation on Triggers](https://dev.mysql.com/doc/refman/8.0/en/triggers.html)
[MySQL Sakila Database](https://dev.mysql.com/doc/sakila/en/) 
[MySQL Stored Procedure Tutorial](https://www.mysqltutorial.org/mysql-stored-procedure/)
[MySQL Triggers Tutorial](https://www.mysqltutorial.org/mysql-triggers/)
[Working with MySQL Stored Procedures - Simple Talk](https://www.red-gate.com/simple-talk/databases/mysql/working-with-mysql-stored-procedures/)

## Flashcards
[Stored Procedures and Triggers - AnkiWeb](https://ankiweb.net/shared/info/1879542724?cb=1738340208508)
