2022-08-05 20:30:04 +01:00
---
2022-08-16 11:58:34 +01:00
categories:
2022-08-05 20:30:04 +01:00
- Databases
2022-08-21 11:00:04 +01:00
- Programming Languages
2022-08-16 11:58:34 +01:00
tags: [SQL]
2022-08-05 20:30:04 +01:00
---
# SQL: Language structure
2022-12-06 09:29:41 +00:00
The structure or syntax of SQL is composite and mirrors that of a natural or logical language. There are overall statements (queries) which subdivide hierarchially into clauses, predicates, and expressions.
2022-08-05 20:30:04 +01:00
2022-12-06 09:29:41 +00:00
## Query
2022-08-05 20:30:04 +01:00
2022-12-06 09:29:41 +00:00
- A statement that updates or retrieves data from a table based on passed-in criteria
- The highest level in the syntax tree, equivalent to a sentence in natural language
- Examples:
- `SELECT`
- `UPDATE`
- `DELETE`
- Applied example:
- `SELECT name FROM model`
2022-08-05 20:30:04 +01:00
2022-12-06 09:29:41 +00:00
## Clause
2022-08-05 20:30:04 +01:00
2022-12-06 09:29:41 +00:00
- Typically provides parameters for a given query
- For example running a query against a specific table (`FROM` ) that satisfies certain conditions (`WHERE` )
2022-08-05 20:30:04 +01:00
2022-12-06 09:29:41 +00:00
## Predicates
2022-08-05 20:30:04 +01:00
2022-12-06 09:29:41 +00:00
- A logical or numerical condition which is passed to a given clause.
- For example `WHERE` a given condition obtains
2022-08-05 20:30:04 +01:00
2022-12-06 09:29:41 +00:00
### Expression
2022-08-16 11:58:34 +01:00
2022-12-06 09:29:41 +00:00
- The lowest level of the hierarchy: field, row names etc