When would you want to use a dbt schema tests (unique, not_null, accepted_values, & relationships) when you could instead use SQL schema constraints?
For example, here are some SQL schema constraints that could replace each of the dbt schema tests:
unique:UNIQUEconstraintnot_null:NOT NULLconstraintaccepted_values:FOREIGN KEYconstraint to a lookup tablerelationships:FOREIGN KEYconstraint to another table
Advertisement
Answer
You can’t have the above-listed table constraints on a view, or a CTE. The value of dbt is that users are allowed to build a DAG of SELECT queries without having to worry about DDL or configuration. At a later point of time they can be configured to be tables instead of the default view, and no syntax need be changed.