# Stored Procedure

> A small program saved in the database. The app calls it by its name.

**Field:** Software Development  
**Category:** Databases  
**Also known as:** Stored Proc, SQL Procedure

## Think of it like

Think of it like a recipe card kept in the kitchen. The cook can use it without you reading it out.

## Definition

A stored procedure is a small program saved inside the database itself. It can run several SQL steps, use ifs and loops, and take inputs. The app calls it by name instead of sending each step. Because it runs next to the data, it can be fast for big jobs. Each database has its own way to write them, so they are hard to move to another one.

## Example

Emma's bank has a stored procedure called close_month. Each night it adds interest to 80,000 accounts, and the data never leaves the server.

## Why it matters

Some jobs are much faster when they run where the data lives. Stored procedures do that.

## Common mistake

Hiding all the business rules in stored procedures. They are hard to test, review and move to a new database.

## Three principles

- **Lives in the database.** Saved there, run there.
- **Called by name.** The app sends one call.
- **Hard to move.** Each database writes them its own way.

## Related terms

- [Structured Query Language (SQL)](https://learn.benibix.com/term/development/sql)
- [Database](https://learn.benibix.com/term/development/database)
- [Function](https://learn.benibix.com/term/development/function)
- [Database Transaction](https://learn.benibix.com/term/development/transaction)

---

Source: https://learn.benibix.com/term/development/stored-procedure
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
