EXIN SQL Foundation key terms
EXIN SQL Foundation · Get comfortable with the vocabulary.
- Relational database
- Related: Table, Primary key, Foreign key
A collection of data organised as tables of rows and columns, where relationships between tables are expressed through shared key values rather than physical pointers. Queries combine these tables at run time.
- Table
- Related: Row, Column, Relational database
The basic storage structure in a relational database: a named set of rows, each row having the same set of named columns with a defined data type per column. Also called a relation or entity.
- Row
- Related: Table, Column, Primary key
A single record in a table, holding one value for each column. Also called a tuple or record. Rows are unordered in the relational model; only an ORDER BY clause gives a result a defined sequence.
- Column
- Related: Row, Data type, Table
A named attribute of a table that holds one value per row, with a declared data type and optional constraints. Also called a field or attribute. All values in a column share the same type.
- Primary key
- Related: Unique constraint, Foreign key, Candidate key
A column or set of columns whose values uniquely identify each row in a table. It must be unique and non-null, and a table can have only one primary key, though that key may span several columns.
- Candidate key
- Related: Primary key, Unique constraint, Functional dependency
Any minimal set of columns that could serve as the primary key because it uniquely identifies every row. One candidate key is chosen as the primary key; the others are usually enforced as unique constraints.
- Foreign key
- Related: Primary key, Referential integrity, Constraint
A column or set of columns in one table whose values must match a candidate key value in another table, or be null. It enforces referential integrity between parent and child tables.
- Referential integrity
- Related: Foreign key, Constraint, ON DELETE CASCADE
The rule that every non-null foreign key value must correspond to an existing key value in the referenced table. The database rejects inserts, updates and deletes that would break this rule.
- Unique constraint
- Related: Primary key, Constraint, Candidate key
A rule that no two rows may hold the same value in the specified column or column combination. Unlike a primary key, a unique constraint usually permits null values and a table may have several of them.
- NOT NULL constraint
- Related: NULL, Constraint, Primary key
A column rule that forbids the absence of a value, so every row must supply a value for that column. It is a column-level check and is implied automatically by a primary key.
- CHECK constraint
- Related: Constraint, DEFAULT constraint, Data type
A rule attached to a column or table that a Boolean condition must hold for every row, for example a quantity greater than zero. The database rejects any insert or update that makes the condition false.
- DEFAULT constraint
- Related: INSERT statement, NULL, CHECK constraint
A value the database supplies automatically when an INSERT statement omits the column. It applies only when no value is given; explicitly inserting NULL stores NULL rather than the default.
- NULL
- Related: Three-valued logic, NOT NULL constraint, COALESCE
A marker meaning that a value is unknown or not applicable, distinct from zero or an empty string. Comparisons with NULL yield unknown, so tests must use IS NULL or IS NOT NULL.
- Three-valued logic
- Related: NULL, WHERE clause, COALESCE
The rule that SQL conditions evaluate to true, false or unknown, with unknown arising whenever NULL takes part in a comparison or arithmetic expression. A WHERE clause keeps only rows whose condition is true.
- COALESCE
- Related: NULL, CASE expression, Three-valued logic
A function returning the first of its arguments that is not null, or null if all are null. Commonly used to substitute a default for missing values in query output.
- Data type
- Related: Column, CAST, CHAR versus VARCHAR
The declared category of values a column may hold, such as integer, decimal, character string, date or Boolean. The type determines allowed operations, storage size and which implicit conversions the database permits.
- CHAR versus VARCHAR
- Related: Data type, CAST, TRIM
CHAR stores fixed-length strings padded with spaces to the declared length, while VARCHAR stores variable-length strings up to a maximum. CHAR suits uniform codes; VARCHAR suits names and addresses of varying length.
- CAST
- Related: Data type, Implicit conversion, Date function
An operator or function that converts a value from one data type to another, for example turning a string into a number or a date. It may be explicit in the statement or applied implicitly by the database.
- Implicit conversion
- Related: CAST, Data type, Index
Automatic type conversion the database performs when operands of different types meet in an expression or comparison. It can silently change results or prevent an index from being used, so explicit conversion is safer.
- CREATE TABLE
- Related: ALTER TABLE, DROP TABLE, Constraint
The DDL statement that defines a new table by naming it and listing its columns with data types and constraints. Variants can also copy structure from an existing table or create the table only if absent.
- ALTER TABLE
- Related: CREATE TABLE, DROP TABLE, Constraint
The DDL statement that changes an existing table's definition, for example adding or dropping a column, changing a data type, or adding and removing constraints. Existing data may be validated or converted.
- DROP TABLE
- Related: CREATE TABLE, TRUNCATE, DELETE statement
The DDL statement that removes a table and its definition permanently. Unlike DELETE, it removes the structure as well as all rows, and in most products it cannot be rolled back after commit.
- TRUNCATE
- Related: DELETE statement, DROP TABLE, Transaction
A statement that removes all rows from a table quickly while keeping the table definition. It is usually treated as DDL, often cannot be filtered by WHERE, and resets or ignores certain identity counters.
- View
- Related: Materialised view, CREATE VIEW, SELECT statement
A named, stored query that behaves like a virtual table. It holds no data of its own; each reference runs the underlying SELECT, which can simplify complex queries or restrict which columns users see.
- Materialised view
- Related: View, Aggregate function, Index
A view whose result is physically stored and must be refreshed to reflect changes in base tables. It speeds up expensive aggregations at the cost of stale data between refreshes.
- Index
- Related: Query execution plan, Primary key, Unique constraint
An auxiliary structure, usually a balanced tree, that lets the database find rows without scanning the whole table. It speeds up lookups and joins but adds storage and slows inserts, updates and deletes.
- SELECT statement
- Related: WHERE clause, ORDER BY clause, GROUP BY clause
The statement that retrieves data, built from clauses evaluated in a logical order: FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY. Only the SELECT and FROM parts are mandatory.
- WHERE clause
- Related: HAVING clause, Three-valued logic, SELECT statement
The SELECT clause that filters individual rows before grouping and before any aggregate is computed. It accepts conditions on columns and expressions but cannot reference aggregate functions.
- ORDER BY clause
- Related: SELECT statement, LIMIT and OFFSET, NULL
The clause that sorts a result set by one or more expressions, ascending by default, with ASC or DESC per column and NULL placement controlled by NULLS FIRST or NULLS LAST. It is the only guaranteed ordering.
- GROUP BY clause
- Related: HAVING clause, Aggregate function, WHERE clause
The clause that collapses rows sharing the same values in the listed expressions into one group each, so aggregate functions report per group. Selected non-aggregated columns must normally appear in the list.
- HAVING clause
- Related: GROUP BY clause, WHERE clause, Aggregate function
The clause that filters groups after GROUP BY and after aggregates are computed, so it may test aggregate results such as COUNT(*) greater than five. Row-level filtering belongs in WHERE instead.
- Aggregate function
- Related: GROUP BY clause, HAVING clause, Window function
A function that condenses many rows into one value per group, such as COUNT, SUM, AVG, MIN and MAX. Most ignore nulls, and COUNT(*) counts rows while COUNT(column) counts non-null values.
- Window function
- Related: Aggregate function, RANK and DENSE_RANK, GROUP BY clause
A function that computes a value across a set of related rows while keeping every row in the output, defined by an OVER clause with optional PARTITION BY and ORDER BY. Examples include ROW_NUMBER and running SUM.
- RANK and DENSE_RANK
- Related: Window function, ORDER BY clause, LIMIT and OFFSET
Window functions that number rows within an ordered partition. RANK leaves gaps after ties, giving 1, 1, 3, while DENSE_RANK gives 1, 1, 2. ROW_NUMBER always assigns distinct consecutive numbers.
- JOIN
- Related: INNER JOIN, LEFT OUTER JOIN, Cartesian product
An operation combining rows from two or more tables on a matching condition. Inner joins keep only matches; outer joins keep unmatched rows from one or both sides with nulls filling the missing columns.
- INNER JOIN
- Related: LEFT OUTER JOIN, JOIN, Foreign key
A join returning only row pairs for which the join condition is true, so rows without a match on either side are dropped. It is the default join type when JOIN is written without a qualifier.
- LEFT OUTER JOIN
- Related: INNER JOIN, JOIN, NULL
A join that keeps every row of the left table, filling columns from the right table with nulls where no match exists. Conditions on the right table in WHERE can silently turn it into an inner join.
- Cartesian product
- Related: JOIN, INNER JOIN, Query execution plan
The result of combining every row of one table with every row of another, produced by a join without a condition or by a cross join. Row counts multiply, so accidental products are a common performance fault.
- Subquery
- Related: EXISTS, Common table expression, View
A SELECT nested inside another statement, usable in the FROM clause, in WHERE with operators such as IN or EXISTS, or as a scalar value. Correlated subqueries reference columns of the outer query and run per outer row.
- EXISTS
- Related: Subquery, IN operator, NULL
A predicate that is true when a correlated subquery returns at least one row. It stops searching at the first match and is often used instead of IN to avoid null-related surprises and improve performance.
- Common table expression
- Related: Subquery, View, SELECT statement
A named temporary result defined with WITH before the main statement and referenced like a table within that statement. It improves readability and can be recursive for hierarchical data.
- Set operator
- Related: SELECT statement, JOIN, ORDER BY clause
An operator combining the results of two queries: UNION removes duplicates, UNION ALL keeps them, INTERSECT returns common rows and EXCEPT or MINUS returns rows of the first query not in the second. Column counts and types must align.
- INSERT statement
- Related: UPDATE statement, DELETE statement, DEFAULT constraint
The DML statement that adds rows to a table, either one row with VALUES or many rows from a SELECT. Omitting the column list requires a value for every column in declared order.
- UPDATE statement
- Related: INSERT statement, DELETE statement, WHERE clause
The DML statement that changes existing values in a table, setting columns to expressions for all rows or only those matching its WHERE clause. Without WHERE it rewrites every row.
- DELETE statement
- Related: TRUNCATE, UPDATE statement, Transaction
The DML statement that removes rows matching its WHERE clause, or all rows if none is given, while keeping the table structure. It can be rolled back and fires delete triggers.
- Transaction
- Related: COMMIT and ROLLBACK, Isolation level, TRUNCATE
A unit of work whose statements either all take effect or none do. It begins implicitly or with BEGIN, ends with COMMIT to make changes permanent or ROLLBACK to undo them, and must satisfy ACID properties.
- COMMIT and ROLLBACK
- Related: Transaction, Isolation level, DELETE statement
The statements that end a transaction: COMMIT saves all changes permanently, ROLLBACK discards them and restores the previous state. Savepoints allow partial rollback within a longer transaction.
- Isolation level
- Related: Transaction, COMMIT and ROLLBACK, Lock
A setting controlling how much one transaction sees of others' uncommitted or newly committed changes. Levels such as READ COMMITTED and SERIALIZABLE trade consistency against concurrency, allowing or preventing dirty reads and phantom rows.
- Lock
- Related: Isolation level, Transaction, Query execution plan
A mechanism by which the database prevents conflicting simultaneous access to a row, page or table. Shared locks permit concurrent reads; exclusive locks block other writers and can cause blocking or deadlock.
- Query execution plan
- Related: Index, Cartesian product, Lock
The database's chosen strategy for running a statement, showing access methods such as full scan or index seek, join algorithms and estimated costs. Reading plans is the main way to diagnose slow queries.
- LIKE operator
- Related: WHERE clause, TRIM, Index
A pattern-matching predicate where percent matches any sequence of characters and underscore matches exactly one. Patterns starting with a wildcard usually prevent index use, and matching is case-sensitive in some products.
- TRIM
- Related: CHAR versus VARCHAR, LIKE operator, Date function
A string function removing leading, trailing or both kinds of a specified character, spaces by default. It is often applied to CHAR columns whose values were padded to fixed length.
- Date function
- Related: CAST, Data type, TRIM
A built-in function that extracts parts of a date, adds intervals or formats values, such as CURRENT_DATE, EXTRACT or DATEADD. Names and behaviour vary between products, so portability requires care.
- CASE expression
- Related: COALESCE, WHERE clause, UPDATE statement
A conditional expression returning one of several values depending on which WHEN condition is true first, with an optional ELSE fallback. It works inside SELECT, WHERE, ORDER BY and UPDATE assignments.
- LIMIT and OFFSET
- Related: ORDER BY clause, Window function, SELECT statement
Clauses restricting a result to a number of rows and skipping a number before returning them, used for paging. Products differ, using TOP, FETCH FIRST or ROWNUM instead, and a stable ORDER BY is essential.
- Constraint
- Related: Primary key, CHECK constraint, Referential integrity
A rule declared on a table or column that the database enforces on every change, covering primary keys, foreign keys, uniqueness, non-null, checks and defaults. Violations cause the statement to fail.
- Functional dependency
- Related: Candidate key, GROUP BY clause, Primary key
A relationship where the value of one set of columns always determines the value of another, written as A determines B. It underpins normalisation and explains why some columns must appear in GROUP BY.
- Normalisation
- Related: Functional dependency, Candidate key, Referential integrity
The process of structuring tables to reduce redundancy and update anomalies by applying normal forms up to third normal form or beyond. Each step removes a class of dependency between columns.
- IN operator
- Related: EXISTS, NULL, Three-valued logic
A predicate true when a value equals any member of a list or the rows returned by a subquery. NOT IN behaves unexpectedly when the list contains NULL, because comparisons yield unknown rather than true.
- Alias
- Related: SELECT statement, View, JOIN
A temporary name given to a column or table in a query, written with AS or by juxtaposition. Column aliases label output; table aliases shorten qualified names and are needed when a table is joined to itself.