SQL, short for Structured Query Language, is the language you use to talk to a relational database. With it you ask the database questions, add and change data, and define the tables that hold it.
What a relational database holds
Section titled “What a relational database holds”A relational database keeps its data in tables. Each table holds one kind of thing, such as productions or invoices:
- A row, also called a record, is one of those things: one production, one invoice.
- A column, also called a field, is one fact recorded about every row: a title, an amount, a date.
Tables are linked by sharing values. An invoice records the ID of the production it belongs to, so a query can follow that link from one table to the other. That linking is what “relational” refers to.
The software that stores the tables and runs your SQL is a relational database management system, or RDBMS. PostgreSQL, MySQL, SQL Server, Oracle and SQLite are all examples.
What you can do with SQL
Section titled “What you can do with SQL”- Read data, picking out exactly the rows and columns you need.
- Add, change and remove rows.
- Create databases and tables, and change their structure later.
- Set rules on the data, such as a column that must never be empty.
- Save queries as views or stored procedures, and control who may use them.
One language, several dialects
Section titled “One language, several dialects”SQL has been an ANSI standard since 1986 and an ISO standard since 1987. Every major database supports the core of it, such as SELECT, INSERT, UPDATE, DELETE and WHERE, in the same way. Beyond that core, each product adds features and spellings of its own. These pages point out the differences where they matter.
The example database
Section titled “The example database”The examples on these pages use a small, invented database for a film and TV production company, with four tables.
Productions, one row per film or series:
| ProductionID | Title | Format | Country | Budget |
|---|---|---|---|---|
| 1 | The Lantern Keepers | Drama series | UK | 18,500,000 |
| 2 | Quarry Lane | Feature film | UK | 7,200,000 |
| 3 | Saltmarsh | Feature film | Ireland | 3,900,000 |
| 4 | Six Bells | Drama series | UK | 11,000,000 |
| 5 | Fennick’s Return | Documentary | Canada | 850,000 |
Invoices, one row per supplier invoice. ProductionID says which production an invoice belongs to, and PaidDate is empty until the invoice is paid:
| InvoiceID | ProductionID | Supplier | Amount | InvoiceDate | PaidDate |
|---|---|---|---|---|---|
| 1001 | 1 | Hartwell Lighting | 24,600.00 | 2025-03-04 | 2025-04-01 |
| 1002 | 2 | Kestrel Catering | 3,180.00 | 2025-03-06 | 2025-03-28 |
| 1003 | 1 | Ashby Camera Hire | 41,250.00 | 2025-03-11 | |
| 1004 | 4 | Kestrel Catering | 2,940.00 | 2025-03-12 |
Crew, one row per person. ReportsTo holds the CrewID of the person’s manager, and is empty for someone who reports to no one on the list:
| CrewID | Name | Role | Department | DayRate | ReportsTo | ProductionID |
|---|---|---|---|---|---|---|
| 1 | Maya Okafor | Line Producer | Production | 650 | 1 | |
| 2 | Tom Hale | Production Accountant | Accounts | 450 | 1 | 1 |
| 3 | Priya Nair | Assistant Accountant | Accounts | 300 | 2 | 1 |
| 4 | Owen Price | Gaffer | Lighting | 520 | 1 | 1 |
| 5 | Lucy Brennan | Production Accountant | Accounts | 420 | 2 | |
| 6 | Sam Ellis | Camera Operator | Camera | 480 | 2 |
Suppliers, the company’s list of approved suppliers. Not every supplier on it has sent an invoice yet, and not every supplier that has invoiced is on it:
| SupplierID | Name | Service | City |
|---|---|---|---|
| 1 | Hartwell Lighting | Lighting | Manchester |
| 2 | Kestrel Catering | Catering | Bristol |
| 3 | Northgate Transport | Transport | Leeds |