Professional Documents
Culture Documents
Stored Routines
Stored Routines
March, 2023
WHAT ARE STORED ROUTINES?
• Most of what can be done in a routine can be done with manual SQL statements
• Are best suited for slightly modifying data; not the best choice for implementing complicated
business logic
• Should be used for queries that are run semi-regularly
• Not ideal for daily or more use, as client code is usually more efficient and accurate
• Routines take up space, so the more of them there are, the larger your database needs to be
HOW TO STOP MID-EXECUTION
• Say you run into an error partway through your execution of a procedure, either from logic or
data entered by the user
• Instead of having the procedure crash and fail entirely, or fully stop the server, you can have checks
that will catch the errors/logic and exit the procedure early
• This is done by assigning a label to the procedure with the BEGIN statement
• Can then be exited with the LEAVE labelName; command
LEAVE EXAMPLE