Yes, you can combine multiple CHECK constraints on a single column or across multiple columns in a table. Each CHECK constraint can enforce different rules, and they will all be evaluated when data is inserted or updated.
Here’s an example of combining multiple CHECK constraints on a single column:
CREATE TABLE Employees (
id INT PRIMARY KEY,
age INT,
salary DECIMAL(10, 2),
CHECK (age >= 18),
CHECK (salary >= 30000)
);
In this example, the Employees table has two CHECK constraints: one ensures that the age is at least 18, and the other ensures that the salary is at least 30,000.
You can also combine conditions within a single CHECK constraint using logical operators:
CREATE TABLE Employees (
id INT PRIMARY KEY,
age INT,
salary DECIMAL(10, 2),
CHECK (age >= 18 AND salary >= 30000)
);
In this case, the CHECK constraint ensures that both conditions must be satisfied for the row to be valid.
