Complete the code to add a CHECK constraint that ensures age is at least 18.
CREATE TABLE users (id INT, age INT [1] chk_age CHECK (age >= 18));
The CONSTRAINT keyword is used to name or define a constraint such as CHECK in a table definition.
Complete the code to add a CHECK constraint that ensures salary is positive.
ALTER TABLE employees ADD [1] chk_salary CHECK (salary > 0);
The CONSTRAINT keyword is used to add a CHECK constraint to an existing table.
Fix the error in the CHECK constraint that should ensure quantity is non-negative.
CREATE TABLE orders (id INT, quantity INT [1] CHECK (quantity >= 0));
The CHECK keyword must be followed by parentheses enclosing the condition. The code is missing parentheses around quantity >= 0.
Fill both blanks to create a CHECK constraint that ensures rating is between 1 and 5 inclusive.
CREATE TABLE reviews (id INT, rating INT [1] chk_rating CHECK (rating [2] 1 AND rating <= 5));
Use CONSTRAINT to define the constraint and >= to check rating is at least 1.
Fill all three blanks to add a named CHECK constraint that ensures price is positive and less than 1000.
ALTER TABLE products ADD [1] price_check [2] CHECK (price [3] 0 AND price < 1000);
Use CONSTRAINT to name the constraint, CHECK to define it, and > to ensure price is positive.