Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A database constraint involves a condition that must be satisfied when the database is updated. In SQL, if a constraint condition evaluates to false then the update fails, the data remains unchanged and the DBMS generates an error.</p> <p>Both <code>CHECK</code> and <code>ASSERTION</code> are database constraints defined by the SQL standards. An important distinction is that a <code>CHECK</code> is applied to a specific base table, whereas an <code>ASSERTION</code> is applied to the whole database. Consider a constraint that limits the combined rows in tables <code>T1</code> and <code>T2</code> to a total of 10 rows e.g. </p> <pre><code>CHECK (10 &gt;= ( SELECT COUNT(*) FROM ( SELECT * FROM T1 UNION SELECT * FROM T2 ) AS Tn )) </code></pre> <p>Assume the tables are empty. If this was applied as an <code>ASSERTION</code> only and a user tried to insert 11 rows into <code>T1</code> then then the update would fail. The same would apply if the constraint was applied as a <code>CHECK</code> constraint to <code>T1</code> only. However, if the constraint was applied as a <code>CHECK</code> constraint to <code>T2</code> only the constraint would succeed because a statement targeting <code>T1</code> does not cause the constraints applied to <code>T1</code> to be tested.</p> <p>Both an <code>ASSERTION</code> and a <code>CHECK</code> may be deferred (if declared as <code>DEFERRABLE</code>), allowing for data to temporarily violate the constraint condition, but only within a transaction.</p> <p><code>ASSERTION</code> and <code>CHECK</code> constraints involving subqueries are features outside of core Standard SQL and none of the major SQL products support these features. MS Access (not exactly an industrial-strength product) supports <code>CHECK</code> constraints involving subqueries but not deferrable constraints plus constraint testing is always performed on a row-by-row basis, the practical consequences being that the functionality is very limited.</p> <p>In common with <code>CHECK</code> constraints, a trigger is applied to a specific table. Therefore, a trigger can be used to implement the same logic as a <code>CHECK</code> constraint but not an <code>ASSERTION</code>. A trigger is procedural code and, unlike constraints, the user must take far more responsibility for concerns such as performance and error handling. Most commercial SQL products support triggers (the aforementioned MS Access does not).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload