Bird
0
0

Why does this statement cause an error?

medium📝 Debug Q7 of 15
SQL - Table Constraints

Why does this statement cause an error?

CREATE TABLE employees (id INT NOT NULL, name VARCHAR(50) NOT NULL, age INT NOT NULL DEFAULT NULL);
AYou cannot set DEFAULT NULL on a NOT NULL column
BThe data type INT is invalid
CThe table name is reserved
DNOT NULL cannot be combined with VARCHAR
Step-by-Step Solution
Solution:
  1. Step 1: Understand NOT NULL and DEFAULT NULL conflict

    A NOT NULL column cannot have DEFAULT NULL because it contradicts the constraint.
  2. Step 2: Analyze the statement

    The age column is NOT NULL but has DEFAULT NULL, causing an error.
  3. Final Answer:

    You cannot set DEFAULT NULL on a NOT NULL column -> Option A
  4. Quick Check:

    NOT NULL columns cannot have DEFAULT NULL [OK]
Quick Trick: NOT NULL columns need non-NULL default or none [OK]
Common Mistakes:
MISTAKES
  • Setting DEFAULT NULL on NOT NULL columns
  • Confusing data types
  • Assuming table name causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes