databases
10 minRelational Databases and SQL Foundations: Model the Invariant First
Learn tables, keys, constraints, joins, transactions, and query shape before choosing a specific database engine.
Loading page...
databases
10 minLearn tables, keys, constraints, joins, transactions, and query shape before choosing a specific database engine.
Q&A
Q&AEqual timestamps otherwise make continuation skip or repeat peers.
Carry the full ordering tuple, such as created_at and ID, and match its direction in the continuation predicate. Stable continuation still does not freeze membership across requests.
Q&A
Q&ACOUNT(column) excludes NULL values; COUNT(*) counts input rows.
COUNT(*) counts each row in the group regardless of column values. COUNT(column) counts only rows where that expression is non-NULL. When aggregates look low, check nullability and join multiplication before changing the query.
Q&A
Q&AWindow values are computed after WHERE in logical query processing.
WHERE filters source rows before window calculations are available. Put the window expression in a common table expression or derived table, then filter its rank in the outer query. This also makes the ranking input set explicit.
Q&A
Q&AWHERE filters input rows before grouping; HAVING filters groups after aggregation.
Use WHERE to remove rows before GROUP BY, such as excluding inactive employees. Use HAVING to filter aggregate results, such as departments with COUNT(*) greater than five. Moving a condition between them can change both meaning and query work.
databases
10 minUnderstand transaction conflicts, lock waits, isolation anomalies, and safe retry boundaries across relational databases.
Q&A
Q&AA primary key gives each row a stable identity; it does not replace domain-level uniqueness constraints.
A primary key lets the database and applications refer to one row unambiguously and lets foreign keys express relationships. Add separate unique constraints for business rules such as one account per email. A generated ID alone does not prevent duplicate domain entities.
Q&A
Q&AInnoDB secondary-index entries carry the primary-key value used to find the clustered row.
InnoDB organizes table rows by the clustered primary key. Secondary indexes store their indexed columns plus the primary-key value, so a query requesting columns absent from the secondary index may need a second lookup. Wide primary keys therefore increase the footprint of every secondary index.