Bird
0
0

Given the table employees with columns id INT PRIMARY KEY and name VARCHAR(100) NOT NULL, what happens when you run this query?

medium📝 query result Q13 of 15
SQL - Table Constraints

Given the table employees with columns id INT PRIMARY KEY and name VARCHAR(100) NOT NULL, what happens when you run this query?

INSERT INTO employees (id, name) VALUES (1, NULL);
AThe query fails with an error due to NOT NULL constraint.
BThe name column defaults to an empty string.
CThe row is inserted with a NULL name.
DThe row is inserted but name is ignored.
Step-by-Step Solution
Solution:
  1. Step 1: Understand NOT NULL behavior on insert

    NOT NULL means the column cannot accept NULL values during insert or update.
  2. Step 2: Analyze the insert statement

    The query tries to insert NULL into the name column, violating the NOT NULL constraint, causing an error.
  3. Final Answer:

    The query fails with an error due to NOT NULL constraint. -> Option A
  4. Quick Check:

    NOT NULL rejects NULL inserts [OK]
Quick Trick: Inserting NULL into NOT NULL column causes error [OK]
Common Mistakes:
MISTAKES
  • Assuming NULL is converted to empty string
  • Thinking the row inserts ignoring NULL
  • Confusing NOT NULL with default values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes