Stored Procedures and Functions

Lesson 19 of 20

Store whole SQL mini-programs inside the database — then run them with one CALL instead of ten statements.

The big picture

Programs that live in the database

Instead of sending the same five statements from every app, save them once inside the database under a name — then call them like a function.

Stored procedure

CREATE PROCEDURE saves a named block of SQL in the database itself, ready to run again and again.

Parameters

IN parameters are inputs filled at call time — one procedure can serve every employee.

CALL

CALL give_raise(Dev, 5000) runs the stored body with your arguments plugged in.

Functions return

A stored function is the sibling that RETURNS a value you can use right inside a SELECT.