SQL, originally an abbreviation for Structured Query Language, is a specialised language used primarily to define, manipulate, query and control data in relational database management systems. It provides a declarative way to describe what information should be retrieved or changed without normally requiring the programmer to specify the database engine's internal algorithm for performing the operation.
SQL operates on concepts such as databases, schemas, tables, columns, rows, keys, constraints, indexes, views and transactions, with the relational model providing its conceptual foundation. A typical SQL statement can retrieve selected rows from one or more tables, insert new records, update existing records or delete records. SQL is therefore fundamentally a data-management language rather than a general-purpose programming language, although many database systems extend it with procedural features.
SQL developed from work on relational database systems at IBM in the 1970s. The language was initially called SEQUEL, associated with IBM's System R research project, before the name became SQL. The relational database model itself was introduced by Edgar F. Codd in a 1970 paper, establishing mathematical ideas involving relations, tuples and attributes that strongly influenced subsequent database technology. SQL was later standardised by ANSI and ISO, producing successive standards while commercial database products developed their own extensions. Consequently, SQL is not a single perfectly uniform implementation: products such as PostgreSQL, MySQL, Microsoft SQL Server, Oracle Database and SQLite share a substantial common language but differ in syntax, data types, functions, procedural facilities and implementation behaviour.
A central characteristic of SQL is its declarative nature. A query such as SELECT can specify columns, tables, filtering conditions, grouping and ordering while leaving the database optimiser responsible for choosing an execution strategy. The optimiser may use indexes, join algorithms, statistics, partitioning, caching and other mechanisms to execute logically equivalent queries differently. SQL's relational operations include selection through WHERE conditions, projection through selected columns, joining relations, aggregation through functions such as COUNT and SUM, grouping through GROUP BY and ordering through ORDER BY. JOIN operations are particularly important because relational databases commonly distribute logically related information across multiple normalised tables rather than storing every attribute in one large record.
SQL also encompasses database definition and data modification. Data Definition Language includes statements such as CREATE, ALTER and DROP for defining database objects, while Data Manipulation Language includes SELECT, INSERT, UPDATE and DELETE. Data Control Language commonly includes GRANT and REVOKE for managing permissions, although exact classifications vary between systems. Transaction control includes operations such as COMMIT and ROLLBACK, allowing related changes to be treated as an atomic unit. Relational databases frequently implement transaction guarantees associated with the ACID model: atomicity ensures that a transaction is treated as a unit, consistency preserves defined integrity conditions, isolation controls interaction between concurrent transactions and durability concerns persistence after successful commitment.
SQL's data model includes constraints that allow databases to enforce important rules independently of application code. PRIMARY KEY constraints identify rows, FOREIGN KEY constraints establish relationships between tables, UNIQUE constraints prevent duplicate values in specified columns, NOT NULL prevents missing values where prohibited, and CHECK constraints can restrict values according to specified conditions. Normalisation is a related database-design discipline concerned with structuring relations to reduce inappropriate redundancy and update anomalies.
Indexes can dramatically improve retrieval performance by providing alternative access structures, but they consume storage and impose maintenance costs when data changes. Query performance therefore depends not only on SQL syntax but also on schema design, indexes, cardinality, statistics, data distribution, concurrency and the database engine's execution planner.
SQL is used across applications ranging from websites and business systems to analytics, financial services, scientific software and enterprise information systems. A web application might use SQL to retrieve a customer's orders, while an analytical system might aggregate billions of records by time period or geographic region. SQL can also operate against views, common table expressions and increasingly sophisticated analytical constructs.
Window functions, for example, calculate values across related rows while retaining individual records, enabling tasks such as rankings, running totals and comparisons with neighbouring rows. Common table expressions can structure complex queries into named logical stages, while recursive common table expressions can represent hierarchical or graph-like relationships in systems that support them.
SQL should not be confused with a particular database product or with the relational model itself. SQL is the language; PostgreSQL, MySQL, Oracle Database, Microsoft SQL Server and SQLite are implementations or database products that support SQL with varying degrees of compatibility. SQL also differs from NoSQL technologies, although modern systems frequently combine relational and non-relational approaches. A common misconception is that SQL automatically makes a database secure or fast. Poorly constructed queries can be inefficient, and unsafe construction of SQL statements using untrusted input can create SQL injection vulnerabilities. Parameterised queries, prepared statements, appropriate privilege boundaries and careful database configuration are therefore important security practices.
SQL remains significant because relational databases provide mature mechanisms for consistency, structured relationships, transactions and complex querying. Its limitations include dialect differences, complexity in highly sophisticated queries, impedance mismatches between relational data and object-oriented application models, and challenges associated with extremely large or highly distributed workloads in some architectures. Modern SQL implementations increasingly support JSON, full-text search, spatial data, analytical processing and other capabilities, demonstrating that the language has evolved beyond simple tabular queries. Understanding SQL therefore requires both knowledge of its formal language constructs and an understanding of relational database design, transaction processing, query optimisation, concurrency, integrity, security and the particular implementation being used.