Bird
0
0

Consider the table orders(order_id INT PRIMARY KEY, quantity INT NOT NULL CHECK (quantity > 0)). What happens if you insert (101, NULL)?

medium📝 query result Q5 of 15
SQL - Table Constraints
Consider the table orders(order_id INT PRIMARY KEY, quantity INT NOT NULL CHECK (quantity > 0)). What happens if you insert (101, NULL)?
AInsert fails because quantity cannot be NULL
BInsert succeeds with quantity set to 0
CInsert succeeds ignoring the CHECK constraint
DInsert fails due to PRIMARY KEY violation
Step-by-Step Solution
Solution:
  1. Step 1: Review NOT NULL constraint on quantity

    Quantity must have a value; NULL is not allowed.
  2. Step 2: Analyze the insert with NULL quantity

    Inserting NULL violates NOT NULL constraint, so insert fails.
  3. Final Answer:

    Insert fails because quantity cannot be NULL -> Option A
  4. Quick Check:

    NOT NULL prevents NULL inserts [OK]
Quick Trick: NOT NULL forbids empty values in columns [OK]
Common Mistakes:
MISTAKES
  • Assuming NULL is allowed with CHECK
  • Confusing PRIMARY KEY violation with NOT NULL
  • Thinking CHECK allows NULL values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes