Which of the following statements about primary key constraints in a database is correct?
Think about what makes each row in a table unique and how NULL values affect uniqueness.
A primary key uniquely identifies each row in a table and cannot contain NULL values. This ensures every record is distinct and identifiable.
What is the main purpose of a foreign key constraint in a relational database?
Consider how tables relate to each other and how data consistency is maintained across tables.
A foreign key constraint ensures that the value in one table corresponds to a valid value in another table, preserving the relationship between tables.
Consider a table with a column defined as NOT NULL. What will happen if you try to insert a row without specifying a value for this column?
Think about what NOT NULL means for a column's data.
The NOT NULL constraint requires that a value must be provided for the column. Omitting it causes an error.
Which of the following best describes a key difference between UNIQUE and PRIMARY KEY constraints?
Consider how NULL values are treated differently by these constraints.
A UNIQUE constraint permits multiple NULLs because NULL is not considered equal to NULL, while a PRIMARY KEY does not allow NULLs at all.
A table has a CHECK constraint defined as CHECK (age >= 18). What will happen if an attempt is made to insert a row with age = 16?
Think about what a CHECK constraint enforces on data values.
A CHECK constraint enforces a condition that must be true for all rows. Violating it causes the insertion to fail.