0
0
SQLquery~10 mins

CHECK constraint in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a CHECK constraint that ensures age is at least 18.

SQL
CREATE TABLE users (id INT, age INT [1] chk_age CHECK (age >= 18));
Drag options to blanks, or click blank then click option'
ADEFAULT
BPRIMARY KEY
CCHECK
DCONSTRAINT
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEFAULT instead of CONSTRAINT
Using PRIMARY KEY where CHECK is needed
Omitting CONSTRAINT keyword
2fill in blank
medium

Complete the code to add a CHECK constraint that ensures salary is positive.

SQL
ALTER TABLE employees ADD [1] chk_salary CHECK (salary > 0);
Drag options to blanks, or click blank then click option'
ACONSTRAINT
BINDEX
CDEFAULT
DPRIMARY KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using INDEX instead of CONSTRAINT
Using DEFAULT keyword incorrectly
Omitting CONSTRAINT keyword
3fill in blank
hard

Fix the error in the CHECK constraint that should ensure quantity is non-negative.

SQL
CREATE TABLE orders (id INT, quantity INT [1] CHECK (quantity >= 0));
Drag options to blanks, or click blank then click option'
ACHECK
BCONSTRAINT
CDEFAULT
DPRIMARY KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Missing parentheses around the condition
Using CONSTRAINT without CHECK keyword
Using DEFAULT instead of CHECK
4fill in blank
hard

Fill both blanks to create a CHECK constraint that ensures rating is between 1 and 5 inclusive.

SQL
CREATE TABLE reviews (id INT, rating INT [1] chk_rating CHECK (rating [2] 1 AND rating <= 5));
Drag options to blanks, or click blank then click option'
ACONSTRAINT
B>=
C<=
DDEFAULT
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEFAULT instead of CONSTRAINT
Using < instead of >= for the lower bound
Omitting CONSTRAINT keyword
5fill in blank
hard

Fill all three blanks to add a named CHECK constraint that ensures price is positive and less than 1000.

SQL
ALTER TABLE products ADD [1] price_check [2] CHECK (price [3] 0 AND price < 1000);
Drag options to blanks, or click blank then click option'
ACONSTRAINT
B>
CCHECK
DDEFAULT
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEFAULT instead of CONSTRAINT
Using >= instead of > for price positivity
Omitting CHECK keyword