Introduction to Data Modeling in Snowflake
Nuno Rocha
Director of Engineering



Primary key (PK): Ensures every record in a table has a unique identifier

Primary key (PK): Ensures every record in a table has a unique identifier

PRIMARY KEY: SQL clause to define a column as the unique identifier
CREATE OR REPLACE TABLE products (
    stockcode VARCHAR(255) PRIMARY KEY,
    description VARCHAR(255)
);
Foreign Key (FK): Connects records in different tables to keep the data related

FOREIGN KEY () REFERENCES (): SQL clause to define a column that references the primary key of another table
CREATE OR REPLACE TABLE orders (
    invoiceno INT,
    customerid INT,
    invoicedate DATE,
    unitprice DECIMAL(10, 2),
    quantity INT,
    stockcode VARCHAR(255),
    FOREIGN KEY (stockcode) REFERENCES products(stockcode)
);

PRIMARY KEY: SQL clause to define a column as the unique identifierFOREIGN KEY (...) REFERENCES (...): SQL clause to create a link between two tablesCREATE OR REPLACE TABLE table_name (
      unique_column column_datatype PRIMARY KEY,
      other_columns column_datatype,
      foreign_column column_datatype,
      FOREIGN KEY (foreign_column) REFERENCES foreign_table(PK_from_foreign_table)
);
Introduction to Data Modeling in Snowflake