Bird
0
0

Which of the following is the correct syntax to add a NOT NULL constraint to a column named email in SQL?

easy📝 Syntax Q12 of 15
SQL - Table Constraints
Which of the following is the correct syntax to add a NOT NULL constraint to a column named email in SQL?
AALTER TABLE users ALTER COLUMN email SET NOT NULL;
BALTER TABLE users ADD CONSTRAINT email NOT NULL;
CALTER TABLE users MODIFY email NOT NULL;
DALTER TABLE users CHANGE email TO NOT NULL;
Step-by-Step Solution
Solution:
  1. Step 1: Recall SQL syntax for NOT NULL constraint

    To set a column NOT NULL, the standard syntax is ALTER TABLE table ALTER COLUMN column SET NOT NULL.
  2. Step 2: Match syntax with options

    ALTER TABLE users ALTER COLUMN email SET NOT NULL; matches the correct syntax. Options A, B, and D use incorrect or invalid syntax.
  3. Final Answer:

    ALTER TABLE users ALTER COLUMN email SET NOT NULL; -> Option A
  4. Quick Check:

    ALTER COLUMN ... SET NOT NULL = Correct syntax [OK]
Quick Trick: Use ALTER COLUMN ... SET NOT NULL to add NOT NULL [OK]
Common Mistakes:
MISTAKES
  • Using ADD CONSTRAINT without naming the constraint
  • Using MODIFY or CHANGE which are not standard SQL
  • Confusing syntax with other SQL dialects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes