# Structured Query Language (SQL)
A domain-specific language used in programming and designed for managing data held in a relational database management system (RDBMS) or for stream processing in a relational data stream management system (RDSMS).
**Pronunciation:** /ˈɛs kjuː ɛl/ or /ˈsiːkwəl/
**Difficulty:** Beginner
**Synonyms:** SQL, Sequel
**Categories:** Database, Programming Language, Data Management
**Tags:** Database, RDBMS, Data Query, Data Manipulation, Data Definition, Data Control, Programming Language
Canonical: https://scaleengineer.com/glossaries/structured-query-language
---
## Definitions

- **Standard Language for Relational Databases:** ### Core Concept
**Structured Query Language (SQL)** is a declarative language used for accessing and manipulating data in a relational database. Unlike imperative languages (like C or Python) that describe *how* to do something, SQL describes *what* you want to achieve, and the database engine (the RDBMS) figures out the best way to do it.

### Key Sublanguages
SQL is often divided into several sublanguages based on their function:

*   **Data Query Language (DQL)**: Used to query the database for information. The primary and most famous command is `SELECT`.
*   **Data Definition Language (DDL)**: Used to define and manage all the objects in the database, such as tables, indexes, and views. Commands include `CREATE`, `ALTER`, and `DROP` (e.g., `CREATE TABLE`, `ALTER TABLE`).
*   **Data Manipulation Language (DML)**: Used for adding, deleting, and modifying data within tables. Commands include `INSERT`, `UPDATE`, and `DELETE`.
*   **Data Control Language (DCL)**: Used to control access and permissions to data in the database. Commands include `GRANT` and `REVOKE`.
*   **Transaction Control Language (TCL)**: Used to manage transactions, which are sequences of operations performed as a single logical unit of work. Commands include `COMMIT`, `ROLLBACK`, and `SAVEPOINT`.

### Example Usage
```sql
-- DQL: Select the names and departments of all employees
SELECT name, department FROM employees WHERE salary > 50000;

-- DML: Insert a new employee into the 'employees' table
INSERT INTO employees (id, name, department, salary) VALUES (101, 'John Doe', 'Engineering', 60000);

-- DDL: Create a new table called 'departments'
CREATE TABLE departments (
    id INT PRIMARY KEY,
    name VARCHAR(255) NOT NULL UNIQUE
);

-- DCL: Grant SELECT permission on the employees table to a user
GRANT SELECT ON employees TO 'data_analyst_user';
```

### Synonyms
The term **Sequel** is often used interchangeably with SQL, reflecting its original name.

## Etymology

The name "SQL" is an acronym for Structured Query Language. It was originally developed at IBM under the name SEQUEL (Structured English Query Language) but was later shortened to SQL due to a trademark dispute with the Hawker Siddeley aircraft company, which had a product with a similar name.

## First used

1974

## Historical context

**Early 1970s**: Donald D. Chamberlin and Raymond F. Boyce at IBM developed SQL, then called SEQUEL, after learning about the relational model from Edgar F. Codd's influential paper, "A Relational Model of Data for Large Shared Data Banks". The language was designed to manipulate and retrieve data stored in IBM's original quasi-relational database management system prototype, System R.

**1979**: Relational Software, Inc. (which later became Oracle Corporation) saw the commercial potential and introduced the first commercially available implementation of SQL, Oracle V2, beating IBM to the market.

**1986**: Recognizing the need for a unified standard across different database vendors, the American National Standards Institute (ANSI) adopted SQL as the official standard for relational databases.

**1987**: The International Organization for Standardization (ISO) followed suit, adopting the ANSI SQL standard. This solidified SQL's position as the global standard language for relational database communication.

**Late 1980s and 1990s**: SQL's adoption exploded. Major tech companies like Sybase, Microsoft (with SQL Server), and IBM (with DB2) released their own RDBMS products, all using SQL as their primary interface. This widespread adoption made it a critical skill for developers and database administrators.

**1999 onwards**: The SQL standard has been revised several times to keep up with evolving technology needs. Major revisions like SQL:1999 (also known as SQL3), SQL:2003, SQL:2008, SQL:2011, and SQL:2016 have added significant features, including regular expression matching, XML-related features, window functions, and native JSON support. Despite the standard, most SQL implementations (like PostgreSQL's T-SQL or Oracle's PL/SQL) include proprietary extensions, leading to variations between different database systems.

## Q&A

- **What are the main sublanguages of SQL and what is the purpose of each?:** The main sublanguages are DQL (Data Query Language) for retrieving data (`SELECT`), DDL (Data Definition Language) for defining database structure (`CREATE`, `ALTER`), DML (Data Manipulation Language) for modifying data (`INSERT`, `UPDATE`, `DELETE`), and DCL (Data Control Language) for managing permissions (`GRANT`, `REVOKE`).
- **Is SQL a declarative or imperative programming language, and what does that mean?:** SQL is a declarative language. This means you specify *what* data you want to retrieve or manipulate, not *how* to perform the operation. The database management system's query optimizer is responsible for determining the most efficient execution plan to fulfill the request.
- **What is the difference between `DELETE`, `TRUNCATE`, and `DROP` in SQL?:** `DELETE` is a DML command that removes rows from a table one by one and can be rolled back; it also fires triggers for each deleted row. `TRUNCATE` is a DDL command that quickly removes all rows from a table by deallocating data pages; it is minimally logged and cannot be easily rolled back. `DROP` is a DDL command that completely removes the table's structure, data, and associated objects like indexes and constraints.

## Usage examples

- To retrieve customer information, the developer wrote a complex **Structured Query Language** query with multiple joins.
- Our database administrator uses **SQL** scripts to perform daily backups and maintenance tasks.
- Before we can store any data, we need to use DDL commands in **SQL** to define the table schema.
- She is learning **Sequel** to transition into a data analyst role, as it's fundamental for data extraction and reporting.

## Related terms

- RDBMS
- NoSQL
- Database
- Primary Key
- Foreign Key
- Index
- Transaction

## Popular related terms

- MySQL
- PostgreSQL
- Microsoft SQL Server
- SQLite
- Oracle Database
