70-466 · Question #122
You are created a table named Orders. You need to ensure that every time a new row is added to the Orders table, a user-defined function is called to validate the row before the row is added to the…
The correct answer is D. a CHECK constraint. A CHECK constraint in SQL Server can reference a scalar user-defined function, making it the most direct way to invoke custom validation logic before a row is committed to the table.
Question
Exhibit
Options
- Aa FOREIGN KEY constraint
- Ba data manipulation language (DML) trigger
- Ca DEFAULT constraint
- Da CHECK constraint
How the community answered
(34 responses)- A3% (1)
- B6% (2)
- C3% (1)
- D88% (30)
Why each option
A CHECK constraint in SQL Server can reference a scalar user-defined function, making it the most direct way to invoke custom validation logic before a row is committed to the table.
A FOREIGN KEY constraint enforces referential integrity against a parent table and cannot invoke a user-defined function for custom business-rule validation.
A DML trigger can call a UDF but is a heavier, more complex mechanism that fires after the row is staged; a CHECK constraint is the more direct and best-practice answer for this scenario.
A DEFAULT constraint supplies a column value when none is provided; it performs no validation and cannot call a user-defined function to reject invalid data.
A CHECK constraint can call a scalar user-defined function, so every INSERT or UPDATE automatically runs the UDF and rejects the row if the function returns false. This is enforced declaratively by the database engine with no additional trigger overhead. It is the most targeted and efficient mechanism for pre-insert row validation tied to a UDF.
Concept tested: CHECK constraint invoking user-defined function for validation
Source: https://learn.microsoft.com/en-us/sql/relational-databases/tables/unique-constraints-and-check-constraints
Topics
Community Discussion
No community discussion yet for this question.
