Wednesday, March 23, 2022

Snowflake Constraint Column Details

 At the time of this post, Snowflake did not have any dictionary view that gives the column names for constraints that are defined for a table. 

So, here is what I found to get that list:

show primary keys; --and then get the query id from this and plug it in below query

select "database_name" db_name, "schema_name" schema_name, "table_name" table_name, "column_name" column_name, "key_sequence" key_seq
  from TABLE(RESULT_SCAN('query id from show command above'))
 where not "table_name" like any ('SAN_%', '%_STAGE', '%_STAGE_CLONE', 'BACKUP_%', 'raw_%', 't_raw_%', '_202%')
 order by 1,2,3,5;

Repeat same for unique keys and imported keys(foreign)