Primary Key Constraint

Description

The PRIMARY KEY constraint specifies that a column or columns of a table can contain only unique (non-duplicate), nonnull values.

Click here to navigate to the PostgreSQL documentation page for this syntax.

The use of index parameters is not supported by Snowflake.

Grammar Syntax

[ CONSTRAINT constraint_name ]
PRIMARY KEY ( column_name [, ... ] ) index_parameters
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]

index_parameters are:

[ INCLUDE ( column_name [, ... ] ) ]
[ WITH ( storage_parameter [= value] [, ... ] ) ]
[ USING INDEX TABLESPACE tablespace_name ]

Sample Source Patterns

PostgreSQL

CREATE TABLE films (
    code        char(5),
    title       varchar(40),
    CONSTRAINT code_title PRIMARY KEY(code,title)
);

CREATE TABLE product (
    code        char(5),
    name       varchar(40),
    PRIMARY KEY(code,name) INCLUDE(column1)
);

Snowflake

CREATE TABLE films (
    code        char(5),
    title       varchar(40),
    CONSTRAINT code_title PRIMARY KEY(code,title)
);

CREATE TABLE product (
    code        char(5),
    name       varchar(40),
    PRIMARY KEY(code,name)
-- ** MSC-WARNING - MSC-PG0007 - INCLUDE PARAMETER NOT APPLICABLE. CONSTRAINT INDEX PARAMETERS ARE NOT SUPPORTED IN SNOWFLAKE. **
--                           INCLUDE(column1)
);

Last updated