nerdexam
Microsoft

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.

Build an analysis services database

Question

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 table. What should you use? More than one answer choice may achieve the goal. Select the BEST answer.

Exhibit

70-466 question #122 exhibit

Options

  • Aa FOREIGN KEY constraint
  • Ba data manipulation language (DML) trigger
  • Ca DEFAULT constraint
  • Da CHECK constraint

How the community answered

(34 responses)
  • A
    3% (1)
  • B
    6% (2)
  • C
    3% (1)
  • D
    88% (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.

Aa FOREIGN KEY constraint

A FOREIGN KEY constraint enforces referential integrity against a parent table and cannot invoke a user-defined function for custom business-rule validation.

Ba data manipulation language (DML) trigger

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.

Ca DEFAULT constraint

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.

Da CHECK constraintCorrect

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

#CHECK constraint#row validation#DML trigger#table constraints

Community Discussion

No community discussion yet for this question.

Full 70-466 Practice