
You discover that some records in the Rooms table contain NULL values for the Owner field. You need to ensure that all future records have a value for the Owner field. What should you add?
Show answerHide answer
Correct answer: B a check constraint
Explanation
Explanation:This question tests how to enforce data integrity rules on a specific column in an existing table. The requirement is to ensure that all future records have a value for the Owner field, meaning NULL values must be rejected during insert or update operations. The solution must restrict data entry without altering the column's data type or dropping the table.
✔️ Correct Option:
B. a check constraint
A check constraint enforces logical data integrity by evaluating a Boolean expression on inserted or updated rows. By adding a check constraint such as CHECK (Owner IS NOT NULL), you ensure that any future attempts to insert or update a record without an Owner value will fail and be rejected. This perfectly aligns with the requirement to enforce a value for the Owner field going forward.
❌ Incorrect Options:
A. a foreign key
A foreign key is used to enforce referential integrity between two tables, ensuring that a value in one table matches a value in another table's primary or unique key. It does not validate whether a column contains NULL values and is unrelated to the specific requirement of forcing data entry for a single column.
C. a nonclustered index
A nonclustered index is a performance optimization structure that speeds up data retrieval for queries. It does not enforce any data validation or integrity rules. Adding one will not prevent NULL values from being inserted into the Owner column.
D. a unique constraint
A unique constraint enforces that all values in a column or set of columns are distinct. It does not prevent NULL values; in fact, in SQL Server, a unique constraint typically allows a single NULL value (or multiple, depending on how it is defined). It cannot guarantee that every record has a value.
🔧 Reference:
→ Unique constraints and check constraints — Confirms that check constraints enforce domain integrity by limiting the values that can be placed in a column, such as restricting NULL values.
→ CREATE TABLE (Transact-SQL) — Explains how to define and add constraints to tables to enforce data validity.




.png)




