SQL
Check Constraints
A `CHECK` constraint is an expression that must be satisfied by the values of every row in the table.  
```sql
CREATE TABLE t1 (
id INTEGER PRIMARY KEY,
percentage INTEGER CHECK (0 <= percentage AND percentage <= 100)
);
INSERT INTO t1 VALUES (1, 5);
INSERT INTO t1 VALUES (2, -1);
```  
```console
Error: Constraint Error: CHECK constraint failed: t1
```  
```sql
INSERT INTO t1 VALUES (3, 101);
```  
```console
Error: Constraint Error: CHECK constraint failed: t1
```  
```sql
CREATE TABLE t2 (id INTEGER PRIMARY KEY, x INTEGER, y INTEGER CHECK (x < y));
INSERT INTO t2 VALUES (1, 5, 10);
INSERT INTO t2 VALUES (2, 5, 3);
```  
```console
Error: Constraint Error: CHECK constraint failed: t2
```  
`CHECK` constraints can also be added as part of the `CONSTRAINTS` clause:  
```sql
CREATE TABLE t3 (
id INTEGER PRIMARY KEY,
x INTEGER,
y INTEGER,
CONSTRAINT x_smaller_than_y CHECK (x < y)
);
INSERT INTO t3 VALUES (1, 5, 10);
INSERT INTO t3 VALUES (2, 5, 3);
```  
```console
Error: Constraint Error: CHECK constraint failed: t3
```