Recall & Review
beginner
What is a CHECK constraint in SQL?
A CHECK constraint is a rule that limits the values allowed in a column. It ensures data meets specific conditions before being saved.
Click to reveal answer
beginner
How does a CHECK constraint help maintain data quality?
It prevents invalid data by allowing only values that satisfy the condition defined in the CHECK constraint.
Click to reveal answer
beginner
Write a simple CHECK constraint to ensure age is 18 or older.
CHECK (age >= 18)
Click to reveal answer
intermediate
Can a CHECK constraint use multiple conditions? Give an example.
Yes, using AND or OR. Example: CHECK (age >= 18 AND age <= 65) ensures age is between 18 and 65.
Click to reveal answer
beginner
What happens if you try to insert data that violates a CHECK constraint?
The database rejects the insert or update and shows an error, preventing invalid data from being saved.
Click to reveal answer
What does a CHECK constraint do in a database?
✗ Incorrect
A CHECK constraint limits the values allowed in a column by enforcing a condition.
Which of the following is a valid CHECK constraint for a salary column to be positive?
✗ Incorrect
The correct syntax uses parentheses and a condition: CHECK (salary > 0).
Can a CHECK constraint use logical operators like AND or OR?
✗ Incorrect
CHECK constraints can combine multiple conditions using AND or OR.
What happens if data violates a CHECK constraint during insertion?
✗ Incorrect
The database rejects the insert and shows an error to maintain data integrity.
Which SQL keyword is used to add a CHECK constraint when creating a table?
✗ Incorrect
The CHECK keyword defines the condition for the constraint.
Explain what a CHECK constraint is and how it helps keep data correct.
Think about rules that data must follow before saving.
You got /3 concepts.
Write an example of a CHECK constraint that ensures a product price is greater than zero and less than 1000.
Use AND to combine two conditions inside CHECK.
You got /4 concepts.