ASSERTION is part of the SQL standard (starting with SQL-92) and lets you declare a rule that spans multiple tables or views. Unlike a table-level CHECK constraint, an ASSERTION is evaluated whenever any statement could change data referenced in its search condition. If the condition would become FALSE, the statement is rejected and an error is returned. Because it operates at the schema level, an ASSERTION can enforce complex business rules such as referential counts, mutually exclusive states, or cross-table aggregates without resorting to triggers. Despite its power, most commercial databases have not implemented ASSERTION due to performance and dependency-tracking challenges. In practice, equivalent behavior is usually achieved with triggers, materialized views, or application logic.
assertion_name
(identifier) - Name of the assertion, unique within the schema.search_condition
(boolean) - Expression that must always evaluate to TRUE. May reference multiple base tables, views, and scalar functions.SQL-92 (ISO/IEC 9075:1992)
An ASSERTION guarantees that a complex condition spanning multiple tables is always TRUE. If a data change would break the rule, the operation fails.
No. Although the keyword appears in the SQL standard, popular engines have not implemented it. Use triggers or application logic as a workaround.
Yes, the standard allows aggregates in the search condition as long as the overall expression is deterministic and evaluates to a boolean.
Use DROP ASSERTION assertion_name; to remove the constraint and its enforcement.