REFERENTIAL_INTEGRITY_COUNT

functionsupportedGovernance (policies, tags, data quality)Enterprise+

docs.snowflake.com ↗

Data metric functions

Returns the count of rows in the source table where the column value does not have a corresponding match in the referenced table. These unmatched rows are known as orphaned rows and represent violations of referential integrity. If you specify more than one column argument, returns the count of rows where the combination of the specified source columns does not match any row in the referenced table based on the corresponding reference columns. Data Quality Monitoring requires Enterprise Edition. To inquire about upgrading, please contact Snowflake Support.

Syntax

SNOWFLAKE.CORE.REFERENTIAL_INTEGRITY_COUNT ON ( <column>, TABLE(<ref_table>(<ref_column>)) )

For compound (multi-column) keys

SNOWFLAKE.CORE.REFERENTIAL_INTEGRITY_COUNT ON (
  <column1>, <column2>, ...,
  TABLE(<ref_table>(<ref_column1>, <ref_column2>, ...))
)

Parameters

NameRequiredDescription
columnrequiredSpecifies one or more columns in the source table whose values are checked for referential integrity against the referenced table. When multiple source columns are specified, they form a compound key.
TABLE(ref_table(ref_column))requiredSpecifies the referenced (parent) table and column(s) to validate against, using the TABLE(...) syntax: ref_table — The fully qualified name of the referenced table (for example, my_db.my_schema.my_table). ref_column — One or more columns in the referenced table that correspond to the source columns. The number and order of source columns must match the number and order of reference columns.

Returns

The function returns a NUMBER value. - A return value of 0 means every row in the source table has a corresponding match in the referenced table. Referential integrity is fully satisfied. - A return value of N > 0 means there are N rows in the source table that do not have a matching row in the referenced table. These N rows are considered orphaned.

Usage notes

Allowed data types

The columns specified in the column and ref_column arguments can contain any of the following data types: - DATE - FLOAT - NUMBER - TIMESTAMP_LTZ - TIMESTAMP_NTZ - TIMESTAMP_TZ - VARCHAR