Exam4Training

Which of the following table constraints that can be enforced on Delta lake tables are supported?

Which of the following table constraints that can be enforced on Delta lake tables are supported?
A . Primary key, foreign key, Not Null, Check Constraints
B . Primary key, Not Null, Check Constraints
C . Default, Not Null, Check Constraints
D . Not Null, Check Constraints
E . Unique, Not Null, Check Constraints

Answer: D

Explanation:

The answer is Not Null, Check Constraints https://docs.microsoft.com/en-us/azure/databricks/delta/delta-constraints

✑ CREATE TABLE events( id LONG, ✑ date STRING,

✑ location STRING,

✑ description STRING ✑ ) USING DELTA;

ALTER TABLE events CHANGE COLUMN id SET NOT NULL;

ALTER TABLE events ADD CONSTRAINT dateWithinRange CHECK (date > ‘1900-01-01’);

Note: Databricks as of DBR 11.1 added support for Primary Key and Foreign Key when Unity Catalog is enabled but this is for information purposes only these are not actually enforced. You may ask then why are we defining these if they are not enforced, so especially these information constraints are very helpful if you have a BI tool that can benefit from knowing the relationship between the tables, so it will be easy when creating reports/dashboards or understanding the data model when using any Data modeling tool. Primary and Foreign Key


Graphical user interface, text, application, email

Description automatically generated

Exit mobile version