Databases & Data Storage

Stored Procedure

Definition

A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again. It is a subroutine available to applications that access a relational database system.

Why It Matters

Stored procedures can improve performance by reducing network traffic (you send a single call instead of many SQL statements) and allow for business logic to be encapsulated and reused directly within the database.

Contextual Example

An application needs to perform a complex series of updates to create a new user. Instead of sending multiple SQL statements, it can make a single call to a `CreateNewUser` stored procedure that contains all the necessary logic.

Common Misunderstandings

  • Overuse of stored procedures can make an application less portable, as the logic is tied to a specific database vendor's language (e.g., PL/SQL in Oracle).
  • They can also be a security mechanism, granting users permission to execute the procedure but not to access the underlying tables directly.

Related Terms

Last Updated: December 17, 2025