Databricks Data Engineer Professional Question 176
Single answerYou are designing a Delta Lake table to store sales transaction data. To ensure data integrity, you want to prevent any records with negative transaction amounts from being written to the table. Which approach would you use to enforce this constraint in Delta Lake?
- A
Use a CHECK constraint on the Delta Lake table to ensure transaction amounts are non-negative.
- B
Use a NOT NULL constraint on the transaction amount column.
- C
Create a trigger to automatically delete records with negative transaction amounts.
- D
Write a Delta Live Table (DLT) pipeline with quality rules to filter out invalid data.
Show answer and explanation
Correct answer: A
Explanation
Delta Lake supports CHECK constraints, which are used to enforce specific rules on the data at the table level. By using a CHECK constraint, you can ensure that only valid data (e.g., non-negative transaction amounts) is written to the table, directly addressing the requirement in the scenario. Other options, such as NOT NULL constraints, triggers, or Delta Live Table pipelines, either do not apply to Delta Lake or do not directly enforce constraints on the table itself.
- A. Correct.
This is correct. Delta Lake supports CHECK constraints, which allow you to enforce rules on the data being written to the table, such as ensuring transaction amounts are non-negative.
- B. Incorrect.
This is incorrect. A NOT NULL constraint ensures that a column cannot have null values but does not prevent negative values in the transaction amount column.
- C. Incorrect.
This is incorrect. Delta Lake does not support triggers like traditional relational databases. This approach is not applicable in this scenario.
- D. Incorrect.
This is incorrect. While Delta Live Tables (DLT) can enforce quality rules, the question specifically asks about adding constraints to the Delta Lake table itself, not implementing a separate pipeline.