Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

PK and FK syntax to make my script idempotent

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;

0 2 100
2 REPLIES 2