Structured Query Language (SQL)

SQL (Structured Query Language) is a standard programming language for managing and manipulating data held in relational database management systems (RDBMS).

SQL (Structured Query Language) is a domain-specific language used for managing and querying data held in relational [database](/en/terms/relational-database) management systems (RDBMS). It is a declarative language, meaning users specify what data they want, and the database engine determines how to retrieve or manipulate it. The core components of SQL include Data Definition Language (DDL) for defining database schemas (e.g., CREATE TABLE, ALTER TABLE), Data Manipulation Language (DML) for inserting, updating, and deleting data (e.g., INSERT, UPDATE, DELETE), and Data Control Language (DCL) for managing permissions (e.g., GRANT, REVOKE). The most commonly used part is the Data Query Language (DQL), primarily the SELECT statement, which allows complex data retrieval through filtering (WHERE), sorting (ORDER BY), aggregation (GROUP BY), and joining multiple tables based on defined relationships. SQL databases store data in tables consisting of rows (records) and columns (attributes), enforcing data integrity through constraints like primary keys, foreign keys, and unique constraints. Standardization efforts (e.g., by ANSI/ISO) ensure a degree of interoperability, although specific RDBMS vendors (like Oracle, MySQL, PostgreSQL, SQL Server) implement proprietary extensions and variations.

        graph LR
  Center["Structured Query Language (SQL)"]:::main
  Rel_python["python"]:::related -.-> Center
  click Rel_python "/terms/python"
  Rel_javascript["javascript"]:::related -.-> Center
  click Rel_javascript "/terms/javascript"
  Rel_data_analysis["data-analysis"]:::related -.-> Center
  click Rel_data_analysis "/terms/data-analysis"
  classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
  classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
  classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
  classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
  linkStyle default stroke:#4b5563,stroke-width:2px;

      

🧒 Explain Like I'm 5

SQL is like a special set of commands you use to talk to a super organized digital filing cabinet, asking it to find, add, change, or remove specific pieces of information.

🤓 Expert Deep Dive

The relational model underpinning SQL relies on Codd's 12 rules, ensuring data integrity and consistency through concepts like normalization, ACID transactions (Atomicity, Consistency, Isolation, Durability), and referential integrity enforced via foreign keys. SQL's declarative nature allows for query optimization by the database engine, which employs sophisticated algorithms (e.g., cost-based optimizers) to determine the most efficient execution plan, often involving index usage, join strategies (hash, merge, nested loop), and predicate pushdown. While powerful, SQL struggles with hierarchical or graph-like data structures, leading to the rise of NoSQL databases for specific use cases. Performance tuning often involves schema design, indexing strategies, query rewriting, and understanding [transaction isolation levels](/en/terms/transaction-isolation-levels). SQL injection remains a persistent security vulnerability if input is not properly sanitized.

📚 Sources