Create Primary Key command syntax in Snowflake

You can create a Primary key on a Snowflake Table. But, they are not enforced. However, constraints provide valuable metadata. The primary keys and foreign keys enable members of your project team to orient themselves to the schema design and familiarize themselves with how the tables relate with one another

There are three ways to define Primary Key in Snowflake:

  • Inline Column level Primary Key Constraint
  • Table level Primary Key Constraint
  • Alter table to add Primary Key constraint to an existing table

Inline Column level Primary Key Constraint

CREATE TABLE Employee_table 
(
id INT PRIMARY KEY,
NAME VARCHAR(10),
address VARCHAR(100)
); 

Table level Primary Key Constraint

CREATE TABLE Employee_table 
(
id INT,
NAME VARCHAR(10),
address VARCHAR(100),
PRIMARY KEY (id)
);

Alter table to add Primary Key constraint to an existing table

ALTER TABLE Employee_table ADD PRIMARY KEY (id);

nVector

posted on 05 Apr 20

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds