Which statements are true regarding constraints?
-
A foreign key cannot contain NULL values.
-
A column with the UNIQUE constraint can contain NULL values.
-
A constraint is enforced only for the INSERT operation on a table.
-
A constraint can be disabled even if the constraint column contains data.
To answer this question, the user needs to know about the concept of constraints in databases.
A. This statement is true. If a foreign key column contains null values, it cannot reference any primary key values in the referenced table, resulting in a violation of referential integrity. Hence, a foreign key cannot contain NULL values.
B. This statement is true. A column with the UNIQUE constraint can contain NULL values because the UNIQUE constraint only enforces the uniqueness of non-null values. However, only one null value can be present in the column as multiple null values would not be unique.
C. This statement is false. A constraint is enforced for every operation on a table, including INSERT, UPDATE, and DELETE operations.
D. This statement is true. A constraint can be disabled using the ALTER TABLE statement even if the constraint column contains data. However, disabling a constraint can result in data inconsistency, so it should be done with caution.
Therefore, options A, B, and D are true, and option C is false.
The Answer is: D