Bird
0
0

You want to ensure a username column is unique and never empty. Which combination of constraints should you apply?

hard📝 Application Q8 of 15
SQL - Table Constraints
You want to ensure a username column is unique and never empty. Which combination of constraints should you apply?
ADEFAULT '' and UNIQUE
BPRIMARY KEY only
CCHECK (username <> '') only
DUNIQUE and NOT NULL
Step-by-Step Solution
Solution:
  1. Step 1: Identify constraints for uniqueness and non-empty

    UNIQUE ensures no duplicates; NOT NULL prevents empty (NULL) values.
  2. Step 2: Evaluate other options

    PRIMARY KEY could work but may not be suitable if username is not the key; CHECK alone doesn't prevent NULL; DEFAULT '' allows empty string but not NULL.
  3. Final Answer:

    UNIQUE and NOT NULL -> Option D
  4. Quick Check:

    Unique + Not Null = Unique, non-empty usernames [OK]
Quick Trick: Combine UNIQUE and NOT NULL for unique, filled columns [OK]
Common Mistakes:
MISTAKES
  • Using only CHECK without NOT NULL
  • Assuming DEFAULT prevents NULL
  • Confusing PRIMARY KEY with uniqueness requirement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes