Content deleted Content added
SimLibrarian (talk | contribs) mNo edit summary Tags: Mobile edit Mobile app edit iOS app edit |
Format code |
||
Line 4:
For example, in a table containing products, one could add a check constraint such that the price of a product and quantity of a product is a non-negative value:
If these constraints were not in place, it would be possible to have a negative price (−$30) or quantity (−3 items).
Line 16:
Each check constraint has to be defined in the <code>CREATE TABLE</code> or <code>ALTER TABLE</code> statement using the syntax:
...,
CONSTRAINT ''constraint_name'' CHECK ( ''predicate'' ),
...
If the check constraint refers to a single column only, it is possible to specify the constraint as part of the column definition.
...
''column_name'' ''type'' CHECK ( ''predicate'' ),
...
==NOT NULL constraint==
A <code>NOT [[Null (SQL)|NULL]]</code> constraint is functionally equivalent to the following check constraint with an <code>IS NOT NULL</code> predicate:
Some [[relational database management system]]s are able to optimize performance when the <code>NOT NULL</code> constraint syntax is used as opposed to the <code>CHECK</code> constraint syntax given above.<ref>PostgreSQL 13 Documentation, Chapter 5. ''Data Definition'', Section 5.4.2. ''Not-Null Constraints'', Website: https://www.postgresql.org/docs/13/ddl-constraints.html, Accessed on Jan 9, 2021</ref>
|