How to add primary key and foreign key to a BigQuery?

Viewed 4377

I am trying to learn bigquery but I noticed I cannot add Primary key or Foreign Keys at all.

Here is an example:

CREATE TABLE db.VENDOR 
(
    V_CODE      INT64,
    V_NAME      String NOT NULL,
    V_CONTACT   String NOT NULL,
    V_AREACODE  String NOT NULL,
    V_PHONE     String NOT NULL,
    V_STATE     String NOT NULL,
    V_ORDER     String NOT NULL,
    PRIMARY KEY(V_Code)
);

CREATE TABLE db.PRODUCT 
(
    P_CODE     string Not Null,
    P_DESCRIPT string NOT NULL,
    P_INDATE   DATETIME NOT NULL,
    P_QOH      int64 NOT NULL,
    P_MIN      int64 NOT NULL,
    P_PRICE    NUMERIC NOT NULL,
    P_DISCOUNT NUMERIC NOT NULL,
    V_CODE     int64,

    CONSTRAINT PRODUCT_V_CODE_FK 
        FOREIGN KEY (V_CODE) REFERENCES VENDOR (V_CODE)
);

When I use primary key, I get an error:

Primary Key is not supported

and for the foreign key I get:

Table name "VENDOR" missing dataset while no default dataset is set in the request

Is there anyway to use PK or FK in BigQuery? if yes, How?

1 Answers

Primary keys and foreign keys constraints are not supported. They are not needed for OLAP databases. If you need them, chances are that you need OLTP instead like Cloud SQL or Cloud Spanner

Related