Glossary

Stored Procedure

A stored procedure is a subroutine of SQL logic stored directly in the DBMS and called by name. Unlike a regular query — it is compiled once, executes faster, and can have input/output parameters.

Example (MySQL)

DELIMITER $$
CREATE PROCEDURE GetUserOrders(IN userId INT)
BEGIN
  SELECT o.id, o.total, o.status
  FROM orders o
  WHERE o.user_id = userId
  ORDER BY o.created_at DESC;
END$$
DELIMITER ;

-- Call
CALL GetUserOrders(42);

Benefits

Drawbacks