# SQL/PSM

> ISO standard mainly defining an extension of SQL with a procedural language for use in stored procedures

**Wikidata**: [Q4048876](https://www.wikidata.org/wiki/Q4048876)  
**Wikipedia**: [English](https://en.wikipedia.org/wiki/SQL/PSM)  
**Source**: https://4ort.xyz/entity/sql-psm

## Summary
SQL/PSM is an ISO standard that extends SQL with a procedural language, primarily used for writing stored procedures in database management systems. It was first standardized in 1996 and supports multi-paradigm programming, making it a key tool for database automation and business logic implementation.

## Key Facts
- **Inception**: Standardized in 1996 as part of the SQL:1999 standard.
- **Instance of**: A programming language designed for database procedural logic.
- **Purpose**: Extends SQL with procedural constructs for stored procedures.
- **Paradigm**: Supports multi-paradigm programming, including procedural and declarative elements.
- **Wikipedia presence**: Available in English, Farsi, Korean, and Russian.
- **Related to**: SQL, stored procedures, and database automation.
- **Wikidata ID**: Q1862002 (derived from Freebase ID /m/02rn6ww).

## FAQs
### Q: What is SQL/PSM used for?
A: SQL/PSM is used to write procedural logic within stored procedures in database systems, enabling complex business rules and automation directly in the database.

### Q: Is SQL/PSM still relevant today?
A: Yes, SQL/PSM remains relevant as a standardized way to extend SQL with procedural capabilities, though modern database systems may offer proprietary alternatives.

### Q: Who maintains SQL/PSM?
A: SQL/PSM is maintained by the ISO/IEC as part of the SQL standard, with updates and revisions managed by the SQL standards committee.

### Q: Can SQL/PSM be used outside of stored procedures?
A: While primarily designed for stored procedures, SQL/PSM’s procedural extensions can be used in other database contexts where procedural logic is needed.

### Q: How does SQL/PSM differ from T-SQL or PL/SQL?
A: SQL/PSM is a standardized extension of SQL, whereas T-SQL and PL/SQL are proprietary procedural languages specific to Microsoft and Oracle databases, respectively.

## Why It Matters
SQL/PSM is significant because it provides a standardized way to extend SQL with procedural logic, enabling developers to encapsulate business rules directly within the database. This reduces the need for application-level code, improving performance and consistency. By standardizing procedural SQL, it ensures portability across different database systems, though proprietary extensions like PL/SQL and T-SQL remain widely used. SQL/PSM’s multi-paradigm approach allows for both declarative SQL queries and procedural logic, making it a versatile tool for database automation.

## Notable For
- **Standardization**: One of the first ISO-standardized procedural extensions to SQL.
- **Procedural Logic**: Introduced structured control flow (loops, conditionals) to SQL.
- **Stored Procedures**: Enabled complex database operations to be executed server-side.
- **Multi-Paradigm Support**: Combined declarative SQL with procedural programming.
- **Cross-Database Compatibility**: Designed to work across different database systems supporting SQL.

## Body
### Overview
SQL/PSM (Persistent Stored Modules) is a procedural language extension to SQL defined by the ISO/IEC SQL standard. It was first introduced in SQL:1999 (1996) and later refined in subsequent SQL standards. The language adds procedural constructs to SQL, allowing developers to write stored procedures, functions, and triggers with control structures like loops and conditionals.

### Technical Details
- **Standardization**: SQL/PSM is part of the ISO/IEC 9075 standard, which defines SQL:1999 and later versions.
- **Syntax**: Extends SQL with keywords like `BEGIN`, `END`, `IF`, `WHILE`, and `DECLARE` for procedural logic.
- **Usage**: Primarily used in stored procedures to encapsulate business logic within the database.
- **Implementation**: Supported by database systems that comply with SQL standards, though proprietary extensions (e.g., PL/SQL, T-SQL) are more common in practice.

### Impact
- **Database Automation**: Enabled complex operations to be executed directly on the database server.
- **Performance**: Reduced network traffic by moving logic to the database tier.
- **Portability**: Provided a standardized way to write procedural SQL across different database systems.

### Legacy
- **Evolution**: Later SQL standards (e.g., SQL:2016) continued to refine procedural capabilities, though SQL/PSM remains a foundational concept.
- **Adoption**: Widely adopted in enterprise environments where procedural SQL is required, despite proprietary alternatives.