
Answer-first summary for fast verification
Answer: CONSTRAINT valid_location EXPECT (location != NULL) ON VIOLATION FAIL UPDATE
# DLT Constraints and Validation In Delta Live Tables (DLT), constraints are defined using the `EXPECT` clause to validate data. When a record fails validation, the `ON VIOLATION` clause specifies the action to take: | Action | SQL Syntax | Behavior | |---------------|---------------------------------------------|--------------------------------------------------------------------------| | Warn (default)| `EXPECT ...` | Invalid records are written to the target with a warning. | | Drop | `EXPECT ... ON VIOLATION DROP ROW` | Invalid records are dropped before writing; pipeline continues. | | Fail | `EXPECT ... ON VIOLATION FAIL UPDATE` | Invalid records prevent the update from succeeding; manual intervention required. | ## Requirement Analysis The requirement is to stop the pipeline if the `location` field is missing (`NULL`). This necessitates failing the update when the constraint is violated. Per the official Databricks documentation, the correct syntax is: `ON VIOLATION FAIL UPDATE` ## Option Review - **A**: `location = NULL` is invalid SQL syntax (should be `IS NULL`), and the logic is reversed. ❌ - **B**: ✅ Correct — `location != NULL` (ideally `IS NOT NULL` for SQL correctness) with `ON VIOLATION FAIL UPDATE` matches the requirement and official syntax. - **C**: Uses `ON DROP ROW`, which drops invalid rows instead of failing the pipeline. ❌ - **D**: `ON VIOLATION FAIL` is not valid syntax in DLT SQL. ❌ ## Correct Answer ✅ **B**: ```sql CONSTRAINT valid_location EXPECT (location IS NOT NULL) ON VIOLATION FAIL UPDATE ``` ### Why? - Ensures that if any row has a missing `location`, the update fails. - Matches the official Databricks DLT syntax for failing updates. - Meets the requirement to terminate the pipeline when location details are missing. ## Reference [Databricks Documentation – Action on invalid record](https://docs.databricks.com/en/delta-live-tables/constraints.html)
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
A data engineer has implemented an ETL pipeline using Delta Live Tables to manage travel reimbursement details. They need to ensure the pipeline terminates when location details are missing from employee submissions.
What is the difference between using ON VIOLATION DROP ROW and ON VIOLATION FAIL UPDATE for handling constraint violations in this scenario, and which approach should be used to meet the requirement?
A
CONSTRAINT valid_location EXPECT (location = NULL)
B
CONSTRAINT valid_location EXPECT (location != NULL) ON VIOLATION FAIL UPDATE
C
CONSTRAINT valid_location EXPECT (location != NULL) ON DROP ROW
D
CONSTRAINT valid_location EXPECT (location != NULL) ON VIOLATION FAIL