Foreign keys -or their nearest equivalent - for delta tables in an Azure DataLake

65 Views Asked by At

Foreign keys are in a public preview on DataBricks Foreign keys in public preview on Databricks DataLake

Primary key and foreign key constraints require Unity Catalog and Delta Lake.

You can use primary key and foreign key relationships on fields in Unity Catalog tables. Primary and foreign keys are informational only and are not enforced. Foreign keys must reference a primary key in another table.

You can declare primary keys and foreign keys as part of the table specification clause during table creation. This clause is not allowed during CTAS statements. You can also add constraints to existing tables.

CREATE TABLE T(pk1 INTEGER NOT NULL, pk2 INTEGER NOT NULL,
                CONSTRAINT t_pk PRIMARY KEY(pk1, pk2));
CREATE TABLE S(pk INTEGER NOT NULL PRIMARY KEY,
                fk1 INTEGER, fk2 INTEGER,
                CONSTRAINT s_t_fk FOREIGN KEY(fk1, fk2) REFERENCES T);

. What is the closest equivalent for Azure DataLake? If there is no direct equivalent what patterns have been developed to indicate inter-table dependencies?

0

There are 0 best solutions below