SQL (Structured Query Language) is the standard language for defining, querying and changing data in relational databases — you describe what you want, the database works out how.
Tables, rows and columns
A table has a fixed set of named, typed columns and any number of rows. Every row should be identifiable by a primary key.
SELECT emp_id, name, salary
FROM employees
WHERE salary > 100000
ORDER BY salary DESC;emp_id | name | salary
-------+-------+-------
1 | Asha | 150000
2 | Ravi | 120000
5 | Priya | 110000Read it as English: give me the id, name and salary of employees earning over 1,00,000, highest first. There is no loop, no index handling, no file access — the query optimizer decides how to fetch the rows.
Declarative vs procedural
Relational vocabulary
| Formal term | Everyday term | Meaning |
|---|---|---|
| Relation | Table | A set of tuples with the same attributes |
| Tuple | Row / record | One entity, e.g. one employee |
| Attribute | Column / field | One property, e.g. salary |
| Domain | Data type (+ constraints) | The allowed values of an attribute |
| Degree | Number of columns | employees has degree 7 |
| Cardinality | Number of rows | employees has cardinality 10 |
| Schema | Structure | Table definitions, types, constraints (not the data) |
Why relational databases?
What is the difference between SQL and MySQL?
What does “declarative” mean for SQL?