Primary key vs foreign key
A primary key uniquely identifies a row in its own table, while a foreign key points to a related row in another table.
- Primary key is table identity
- Foreign key creates relationship
- Helps enforce referential integrity
Quick recall
A primary key uniquely identifies a row in its own table, while a foreign key points to a related row in another table.
Joins combine tables directly, while subqueries nest one query inside another; either can be correct depending on clarity and plan quality.
Inner joins return matches, outer joins preserve unmatched rows from one or both sides depending on the type.
Transactions group multiple statements into one atomic unit so partial updates do not leak through on failure.
Window functions compute values across a related set of rows without collapsing them into one row per group.
GROUP BY collects rows by one or more columns so aggregate functions can run per group.
An execution plan shows how the database intends to run a query, including scans, joins, sorts, and index usage.
Denormalization intentionally duplicates or precomputes data to improve read performance.
Normalization reduces redundancy and update anomalies by splitting data into related tables.
Indexes speed reads by avoiding full table scans, but they add write overhead and storage cost.
S3 is durable object storage used for files, backups, logs, static assets, and data lake style workloads.
Rolling replaces instances gradually, while blue-green keeps old and new environments side by side and switches traffic in one move.