Bird
0
0

A table has id INT PRIMARY KEY and score INT CHECK (score BETWEEN 0 AND 100). You want to add a constraint to ensure score is not NULL. What is the best way?

hard📝 Application Q9 of 15
SQL - Table Constraints
A table has id INT PRIMARY KEY and score INT CHECK (score BETWEEN 0 AND 100). You want to add a constraint to ensure score is not NULL. What is the best way?
AAdd CHECK (score IS NOT NULL) constraint
BAdd NOT NULL constraint to score column
CAdd UNIQUE constraint on score
DAdd DEFAULT 0 to score column
Step-by-Step Solution
Solution:
  1. Step 1: Understand NOT NULL vs CHECK for NULL prevention

    NOT NULL explicitly forbids NULL values; CHECK can test conditions but NOT NULL is clearer and standard.
  2. Step 2: Evaluate options

    Adding NOT NULL is best practice; CHECK (score IS NOT NULL) is redundant; UNIQUE unrelated; DEFAULT sets value but doesn't forbid NULL.
  3. Final Answer:

    Add NOT NULL constraint to score column -> Option B
  4. Quick Check:

    NOT NULL forbids NULL values best [OK]
Quick Trick: Use NOT NULL to forbid NULL values, not CHECK [OK]
Common Mistakes:
MISTAKES
  • Using CHECK to forbid NULL instead of NOT NULL
  • Confusing UNIQUE with NULL prevention
  • Assuming DEFAULT forbids NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes