07-28-2021 07:32 AM
Hello,
Please suggest how can we implement Referential Integrity (Primary Key / Foreign Key Constraint) - between different tables defined on Azure Databricks Database.
Basically the syntax to add Primary and Foreign Key constraint in the table definitions.
Thanks in advance for your help.
Regards,
Abhishek
09-02-2021 12:58 PM
You can use constraints: https://docs.microsoft.com/en-us/azure/databricks/delta/delta-constraints
09-03-2021 06:21 AM
according to the docs delta only has not-null and check constraints.
PK/FK constraint support is not mentioned.
Also:
https://issues.apache.org/jira/browse/SPARK-19842
So I'm afraid that it is not yet possible.
05-24-2022 10:55 AM
@Werner Stinckens Hii! I just posted similar question for my project..Can we do pk/fk constraints on delta tables now?
05-24-2022 11:22 PM
nothing has changed so far.
08-15-2022 01:29 AM
08-15-2022 09:31 PM
Is it sad that I was excited to see that in preview, lol
10-14-2022 11:12 AM
10-26-2022 01:06 PM
If you are using Delta Live Table pipelines, the pipeline will check dependencies via the table_constraint using the primary and foreign key definitions and use that to update tables in the proper order to ensure referential integrity. So though not strongly enforced for performance reasons you still get the main benefit of keys when using pipelines. @Qi Su correct me if I'm off here.
10-17-2022 01:13 AM
Is there any alternate way you could suggest to implement and enforce primary key constraint?
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group