NEW
Precompiled database routines that encapsulate SQL logic for performance, security, and reuse.
DESCRIPTION
Stored procedures encapsulate SQL statements on the database server, enabling reusable logic, controlled access, and reduced network latency. They can accept parameters, manage transactions, and return results or status codes. Benefits include performance via execution plan caching and centralized governance of data logic. Drawbacks include portability issues and potential logic sprawl within the database. They are widely used in OLTP systems, ETL tasks, and administrative automation.
ALTERNATIVE DEFINITIONS
Wikipedia
A stored procedure is a subroutine available to applications that access a relational database management system (RDBMS).
Frames stored procedures as callable subroutines within RDBMS.
Microsoft Learn
A stored procedure is a group of one or more Transact-SQL statements or a reference to a Microsoft .NET Framework common runtime language (CLR) method.
Highlights T-SQL grouping and CLR integration in SQL Server.
RELATED TERMS
SQL Triggers Transaction Query Optimization PL/SQL Transact-SQL Access Control Query Execution Plan Parameterization
COMPETING TERMS
User-Defined Function Object-Relational Mapping
KNOWLEDGE AREAS
Data Storage & Operations Data Warehousing & BI Software Engineering Data Engineering
TARGET AUDIENCE
Data Engineer Software Developer Data Architect BI Specialist Data Modeler
EXTERNAL SOURCES
- Wikipedia - Stored procedure
- MySQL - MySQL CREATE PROCEDURE reference
- PostgreSQL - PL/pgSQL language and stored routines
TOP QUESTIONS
Why use Stored Procedures instead of application code?
They reduce network round-trips, centralize logic near data, and can leverage execution plan caching and database security controls.
Category: Relevancy
What are common mistakes with Stored Procedures?
Embedding excessive business logic, poor parameterization, and neglecting version control can harm maintainability and performance.
Category: Mistakes
Do Stored Procedures improve performance?
Often yes, through precompilation, plan reuse, and minimized data movement; however, careful indexing and query design remain crucial.
Category: Opinion
How are Stored Procedures secured?
Use least-privilege execution, sign procedures, and employ parameterized inputs to avoid injection and unauthorized data access.
Category: Requirements
What is a hot topic for Stored Procedures today?
Balancing database-resident logic with microservices and data transformation frameworks like dbt is actively debated.
Category: Topic
How do Stored Procedures compare to User-Defined Functions?
Procedures can perform transactional operations and return multiple result sets; UDFs typically return a value and are side-effect free.
Category: Alternatives
Can Stored Procedures be versioned?
Yes, use migration scripts, semantic naming, and source control; some platforms support schema versioning tools.
Category: Management
When should I avoid Stored Procedures?
Avoid when portability across databases is critical or when logic belongs in application services for agility.
Category: Opinion
How do I test Stored Procedures?
Use unit tests with test data sets, transaction rollbacks, and CI integration to validate logic and performance.
Category: Testing