Questions: SQL: Constraints (PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, DEFAULT)

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A web application validates that a user's age is ≥ 18 in its Python code before inserting into the database, but no CHECK constraint exists on the column. A data analyst runs a direct SQL INSERT through a terminal session. What happens?

AThe Python validation runs automatically for all database connections, including direct SQL sessions
BThe INTEGER column type rejects negative or out-of-range ages automatically
CThe analyst can insert any age value, including negative numbers, because no database constraint prevents it
DThe FOREIGN KEY constraint on a related table prevents the invalid age from being inserted
Question 2 Multiple Choice

Which statement best describes the difference between UNIQUE and PRIMARY KEY constraints?

APRIMARY KEY allows NULLs to accommodate missing identifiers; UNIQUE does not
BUNIQUE ensures no two rows share the same value but permits NULLs; PRIMARY KEY requires NOT NULL and uniquely identifies every row
CThey are functionally identical — PRIMARY KEY is simply a conventional label for the main UNIQUE constraint
DPRIMARY KEY only applies to single-column constraints; UNIQUE is used for multi-column uniqueness
Question 3 True / False

A FOREIGN KEY constraint prevents inserting a row whose foreign key value has no matching primary key in the referenced table.

TTrue
FFalse
Question 4 True / False

A CHECK constraint defined in the database schema is redundant if the application layer already validates the same rule, because the data will be validated before it reaches the database.

TTrue
FFalse
Question 5 Short Answer

Why is it better to enforce business rules like 'age must be positive' and 'email must be unique' as database constraints rather than relying solely on application code?

Think about your answer, then reveal below.