1
votes

as per the official documentation of snowflake, snowflake does not enforce any constraint expect not null. in the create table statement what is the use of enforced or not enforced. sample query:

create or replace table mytable ( c1 varchar constraint pk_constraint primary key enforced, c2 varchar );

https://docs.snowflake.com/en/sql-reference/sql/create-table-constraint.html

1
I believe that most of these options, including setting the keys at all, is primarily for 1) maintaining the metadata in the database, and 2) compatibility with other databases that are migrating to Snowflake. In supporting these parameters, you will not receive errors when running scripts generated by other systems. I don't think they have any additional value.Mike Walton

1 Answers

1
votes

If you keep going deeper in the docs, you'll find the explanation:

Referential integrity constraints in Snowflake are informational and, with the exception of NOT NULL, not enforced. Constraints other than NOT NULL are created as disabled.

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.

Additionally, most business intelligence (BI) and visualization tools import the foreign key definitions with the tables and build the proper join conditions. This approach saves you time and is potentially less prone to error than someone later having to guess how to join the tables and then manually configuring the tool. Basing joins on the primary and foreign keys also helps ensure integrity to the design, since the joins aren’t left to different developers to interpret. Some BI and visualization tools also take advantage of constraint information to rewrite queries into more efficient forms, e.g. join elimination.