SQL Interview: Joins, Keys and Constraints
The questions asked in almost every SQL interview, with short answers you can actually say out loud and the follow up the interviewer will ask next.
Primary, foreign, candidate and surrogate keys.
6 notes tagged
The questions asked in almost every SQL interview, with short answers you can actually say out loud and the follow up the interviewer will ask next.
The two simplest relationships and the single rule that decides where the foreign key goes - plus when a one to one split is actually worth it.
Should the primary key come from the data or be generated? The trade offs, the failure modes of each, and the pattern most teams settle on.
The vocabulary of keys, explained on one table: which columns could identify a row, which one you choose, and what happens to the rest.
What happens to child rows when a parent is deleted or updated, how to choose between RESTRICT, CASCADE and SET NULL, and how to add, drop and disable...
The two constraints that give a database its structure: one that identifies a row, and one that guarantees a reference points at something real.