Difficulty: Easy
Correct Answer: The statement is completely correct for standard relational databases
Explanation:
Introduction / Context:
Constraints in SQL control what values are allowed in columns. Two common constraints are UNIQUE and PRIMARY KEY. Both relate to uniqueness, but they behave differently with respect to NULL values. This question tests whether you understand that difference and can judge the accuracy of the given statement.
Given Data / Assumptions:
Concept / Approach:
A PRIMARY KEY constraint enforces two conditions: the column values must be unique and they must be non null. Therefore, every row must have a non null primary key value. A UNIQUE constraint also enforces uniqueness but typically allows at least one NULL value because NULL represents an unknown value and is not equal to any other value, including another NULL. Many relational databases therefore permit multiple NULLs under a UNIQUE constraint or at least one NULL, depending on implementation, but the general exam level expectation is that UNIQUE can contain NULL while PRIMARY KEY cannot.
Step-by-Step Solution:
Step 1: Recall the definition of PRIMARY KEY: it uniquely identifies each row and cannot contain NULL values.
Step 2: Recall the definition of UNIQUE constraint: it enforces that non null values in the column are unique.
Step 3: Recognize that most database engines treat NULL as a special marker rather than a normal value, so NULL under a UNIQUE constraint is usually allowed.
Step 4: Compare this knowledge with the statement that UNIQUE can contain NULL values while PRIMARY KEY cannot.
Step 5: Conclude that this is the standard understanding taught in certification contexts.
Verification / Alternative check:
You can verify this difference with a simple experiment. Create a table with two columns, one defined as PRIMARY KEY and one with a UNIQUE constraint. Try inserting a row with NULL in the primary key column and you will receive an error. However, inserting NULL into the UNIQUE column is usually allowed, and inserting another row with NULL in that UNIQUE column may also be permitted depending on the database engine. This practical check supports the statement given in the question.
Why Other Options Are Wrong:
The statement is completely incorrect in all relational databases is wrong because the basic rule that primary keys cannot be NULL while unique columns may contain NULL is widely used and documented. The statement is true only in Oracle and false in all other database systems is misleading because similar behavior is present in many systems. The statement is true only when the column length is greater than a fixed size introduces an irrelevant condition. The statement is correct only when the column participates in a foreign key relationship also introduces a condition that does not affect how UNIQUE and PRIMARY KEY constraints handle NULL.
Common Pitfalls:
A common mistake is to assume that UNIQUE and PRIMARY KEY are interchangeable. While both enforce uniqueness, a table can have many UNIQUE columns but only one PRIMARY KEY. Another pitfall is ignoring NULL semantics. In exams, focus on the widely accepted rule: primary keys do not allow NULL, while unique columns may allow NULL values.
Final Answer:
The correct evaluation is that the statement is completely correct for standard relational databases.
Discussion & Comments