| Goal | This query identifies CHECK constraints that contain redundant logic for handling NULLs, a pattern often arising from a misunderstanding of SQL's three-valued logic (TRUE, FALSE, UNKNOWN). A CHECK constraint's condition only fails on FALSE, implicitly permitting NULLs by evaluating comparisons to UNKNOWN. Consequently, an explicit OR column IS NULL clause is tautological and adds no functional value, as demonstrated by the equivalence of CHECK (price IS NULL OR price > 0) and CHECK (price > 0). Removing this superfluous logic improves constraint clarity and eliminates a marginal but unnecessary computational step. |
|---|---|
| Notes | In SQL, CHECK constraints fail only when an expression evaluates to FALSE; any comparison involving a NULL value evaluates to UNKNOWN, which inherently satisfies the constraint and permits the row. Because of this three-valued logic, explicitly combining an IS NULL check with another condition on the exact same column—regardless of whether the null check appears before or after the OR operator—is completely redundant and adds no functional value. This validation rule detects such superfluous logic by verifying that the column tested for nullability is the very same column being evaluated in the alternate branch of the disjunction. Crucially, enforcing that both operands reference the same column prevents false alarms, distinguishing tautological checks from legitimate conditional business rules where a requirement on one column dictates whether a completely different column must be NULL. |
| Type | Problem detection Each row in the result could represent a flaw in the design |
| Reliability | Medium Medium number of false-positive results |
| License | MIT (opens in new tab) |
| Data Source | INFORMATION_SCHEMA+system catalog |
| SQL Query |
|
Fixing Suggestion
Remove ( IS NULL) condition from the check.
Collections
This query belongs to the following collections:
Find problems automatically
Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
| Name | Description |
|---|---|
| Find problems automatically | Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not . |
Categories
This query is classified under the following categories:
CHECK constraints
Queries of this category provide information about CHECK constraints.
Missing data
Queries of this category provide information about missing data (NULLs) in a database.
| Name | Description |
|---|---|
| CHECK constraints | Queries of this category provide information about CHECK constraints. |
| Missing data | Queries of this category provide information about missing data (NULLs) in a database. |