Design and safety quiz

  • Admin
  • 1 min read

Nine questions on keys, constraints, indexes, transactions and views.

SQL

Design and safety quiz

9 questions, instant feedback

Question 1 of 9
Question 1 of 9 What does a primary key guarantee?
Why this is the answer

A primary key identifies each row: no duplicates and no nulls. Most engines also index it.

Question 2 of 9
Question 2 of 9 What does a foreign key enforce?
Why this is the answer

A foreign key points at a row in another table and prevents values that reference nothing.

Question 3 of 9
Question 3 of 9 Which constraint prevents an empty value?
Why this is the answer

NOT NULL rejects NULL. UNIQUE allows one NULL in most engines and prevents duplicates among real values.

Question 4 of 9
Question 4 of 9 What is an index for?
Why this is the answer

An index is a sorted structure the engine can search without scanning the table. Every write must also update it.

Question 5 of 9
Question 5 of 9 Which columns benefit most from an index?
Why this is the answer

Index what queries actually filter, join or sort on. Indexing everything slows writes for no gain.

Question 6 of 9
Question 6 of 9 What does a transaction guarantee?
Why this is the answer

A transaction is atomic: COMMIT saves all its statements, ROLLBACK discards them.

Question 7 of 9
Question 7 of 9 What is a view?
Why this is the answer

A view stores the query, not the rows. It runs when selected, which keeps a complex report in one place.

Question 8 of 9
Question 8 of 9 What does ON DELETE CASCADE do?
Why this is the answer

Cascade removes dependent rows automatically. Without it, deleting a referenced parent fails unless you handle children first.

Question 9 of 9
Question 9 of 9 Which first step limits the damage of a DELETE?
Why this is the answer

Check the predicate returns exactly the rows you mean, then delete inside a transaction so a mistake can be rolled back.

Your answers stay in this browser. Nothing is sent to a server.