CHECK Constraints
Enforce that column values satisfy a Boolean expression at insert and update time.
check constraint column check table check constraint
constraint validation data integrity ddl
| Database | Status | Syntax Family | Min Version |
|---|---|---|---|
| PostgreSQL | full | sql-standard | - |
| MySQL | full | sql-standard | 8.0.16 |
| MariaDB | full | sql-standard | 10.2.1 |
| Oracle | full | sql-standard | - |
| SQL Server | full | sql-standard | - |
| SQLite | full | sql-standard | - |
| Redshift | partial | sql-standard | - |
| DB2 | full | sql-standard | - |
| Snowflake | partial | sql-standard | - |
| BigQuery | none | - | - |
Compare Databases
Database Details
PostgreSQL
full
CREATE TABLE products (
id INT PRIMARY KEY,
price NUMERIC NOT NULL,
CONSTRAINT price_positive CHECK (price > 0)
);- NOT VALID adds the constraint without scanning existing rows; VALIDATE CONSTRAINT validates them later without a long exclusive lock on INSERT/UPDATE.
Docs: CHECK Constraints
MySQL
full
CREATE TABLE products (
id INT PRIMARY KEY,
price DECIMAL(10,2) NOT NULL,
CONSTRAINT price_positive CHECK (price > 0)
);- Enforced since 8.0.16; parsed and ignored before that.
- Cannot reference user-defined or stored functions.
Docs: CHECK Constraints
MariaDB
full
CREATE TABLE products (price DECIMAL(10,2) CHECK (price > 0));- Enforced since 10.2.1; parsed and ignored before that.
Docs: CONSTRAINT
Oracle
full
CREATE TABLE products (
id NUMBER PRIMARY KEY,
price NUMBER NOT NULL,
CONSTRAINT price_positive CHECK (price > 0)
);- SYSDATE and other deterministic functions are allowed; subqueries, other rows, and other tables are not.
Docs: Constraints
SQL Server
full
CREATE TABLE products (
id INT PRIMARY KEY,
price DECIMAL(10,2) NOT NULL,
CONSTRAINT price_positive CHECK (price > 0)
);- ALTER TABLE ... WITH NOCHECK ADD CONSTRAINT adds the constraint without validating existing rows; trigger or FK-based workarounds handle cross-table checks.
Docs: CHECK Constraints
SQLite
full
CREATE TABLE products (
id INTEGER PRIMARY KEY,
price REAL NOT NULL CHECK (price > 0)
);
Redshift
partial
CREATE TABLE products (
id INT PRIMARY KEY,
price DECIMAL(10,2) NOT NULL,
CONSTRAINT price_positive CHECK (price > 0)
);- Accepted and stored in pg_constraint but not evaluated during INSERT, UPDATE, or COPY. Documentation only.
Docs: CREATE TABLE
DB2
full
CREATE TABLE products (
id INT PRIMARY KEY,
price DECIMAL(10,2) NOT NULL,
CONSTRAINT price_positive CHECK (price > 0)
);- Violations raise SQLSTATE 23513.
- SET INTEGRITY FOR t OFF suspends checking for bulk loads; re-enable with SET INTEGRITY ... IMMEDIATE CHECKED.
Docs: CHECK constraints
Snowflake
partial
CREATE TABLE products (
id INT PRIMARY KEY,
price DECIMAL(10,2) NOT NULL,
CONSTRAINT price_positive CHECK (price > 0)
);- Accepted but not evaluated on DML. Only NOT NULL is actually enforced on standard tables.
Docs: Overview of Constraints
BigQuery
none
- Not supported. Enforce at the application layer or in an ELT step.