Databases & SQL interview questions
Show answer
An index is a separate data structure (usually a B-tree) that lets the database find rows by a column without scanning the whole table. It speeds up reads on filtered or sorted columns but uses disk space and slows down inserts and updates. Index the columns you filter, join and sort by; check with
EXPLAIN.Show answer
Atomicity (all or nothing), Consistency (constraints hold), Isolation (concurrent transactions do not see each other's partial work), Durability (committed data survives crashes). Use a transaction whenever several writes must succeed or fail together, for example creating an order and reducing stock.