Bird
0
0

You want to ensure a discount column in a sales table is either NULL or between 0 and 50 inclusive. Which CHECK constraint correctly enforces this?

hard📝 Application Q8 of 15
SQL - Table Constraints
You want to ensure a discount column in a sales table is either NULL or between 0 and 50 inclusive. Which CHECK constraint correctly enforces this?
ACHECK (discount IS NOT NULL AND discount BETWEEN 0 AND 50)
BCHECK (discount >= 0 AND discount <= 50)
CCHECK (discount IS NULL OR (discount >= 0 AND discount <= 50))
DCHECK (discount > 0 AND discount < 50)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement for discount

    Discount can be NULL or a value from 0 to 50 inclusive.
  2. Step 2: Analyze each CHECK condition

    CHECK (discount IS NULL OR (discount >= 0 AND discount <= 50)) allows NULL or values between 0 and 50 inclusive, matching the requirement.
  3. Final Answer:

    CHECK (discount IS NULL OR (discount >= 0 AND discount <= 50)) -> Option C
  4. Quick Check:

    Use OR to allow NULL or valid range [OK]
Quick Trick: Use OR with IS NULL to allow nullable ranges [OK]
Common Mistakes:
MISTAKES
  • Forgetting to allow NULL values
  • Using strict > and < excluding boundaries
  • Requiring discount to be NOT NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes