0
0
SQLquery~5 mins

CHECK constraint in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ACreates a backup of the database
BLimits values in a column based on a condition
CDeletes duplicate rows automatically
DEncrypts data in a column
Which of the following is a valid CHECK constraint for a salary column to be positive?
ACHECK (salary > 0)
BCHECK salary > 0
CCHECK salary = positive
DCHECK (salary IS NOT NULL)
Can a CHECK constraint use logical operators like AND or OR?
AOnly AND is allowed, not OR
BNo, only one condition is allowed
COnly OR is allowed, not AND
DYes, to combine multiple conditions
What happens if data violates a CHECK constraint during insertion?
AThe database automatically fixes the data
BThe data is inserted anyway
CThe insertion fails with an error
DThe data is inserted but marked invalid
Which SQL keyword is used to add a CHECK constraint when creating a table?
ACHECK
BLIMIT
CCONDITION
DRESTRICT
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.