← All languages
SQL keyword of the day
Random

CHECK

Enforce a condition that values in a column must satisfy.

Description

The CHECK constraint enforces a condition on values that can be inserted or updated in a column. Any value that does not satisfy the specified boolean expression will be rejected by the database. CHECK constraints can reference a single column or multiple columns in the same table. They are used to enforce domain integrity by limiting the range of acceptable values, such as requiring a positive price, a valid age range, or a status from a predefined set of values.

Arguments

NameDescriptionOptional
condition A boolean expression that must evaluate to true for the value to be accepted. No

Example

CREATE TABLE products (
  id INT PRIMARY KEY,
  price DECIMAL(10,2) CHECK (price > 0),
  quantity INT CHECK (quantity >= 0)
);
ALTER TABLE employees ADD CONSTRAINT chk_age CHECK (age >= 18 AND age <= 120);