I have below script where I create or replace tables in my pipeline. I add PK and FK constraint after the table are created. How can I make the PK FK statements idempotent? I can't seem to add IF NOT EXISTS as indicated in the docs.
CREATE OR REPLACE TABLE `dataset.X`
PARTITION BY xxxx
CLUSTER BY xxxx AS
SELECT *
FROM
`work_table` where <condition>;
CREATE OR REPLACE TABLE `dataset.Y`
PARTITION BY xxxx
CLUSTER BY xxxx AS
SELECT *
FROM
`work_table2` where <condition>
;
ALTER table dataset.X
ADD primary key(Key) NOT ENFORCED;
ALTER table dataset.Y
ADD FOREIGN KEY(Key) references dataset.X(Key) NOT ENFORCED;