Bird
0
0

Consider the table:

medium📝 query result Q5 of 15
SQL - Table Constraints
Consider the table:
CREATE TABLE orders (id INT, quantity INT CHECK (quantity > 0));

What will be the result of:
INSERT INTO orders VALUES (1, 0);
ARow inserted with quantity 0.
BRow inserted but quantity is set to 1.
CInsertion succeeds but triggers a warning.
DInsertion fails due to CHECK constraint violation.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the CHECK constraint on quantity

    Quantity must be greater than 0 to satisfy the CHECK condition.
  2. Step 2: Analyze the insert with quantity 0

    Quantity 0 violates the CHECK (quantity > 0), so insertion fails.
  3. Final Answer:

    Insertion fails due to CHECK constraint violation. -> Option D
  4. Quick Check:

    CHECK rejects zero when > 0 required [OK]
Quick Trick: CHECK with > excludes zero and negatives [OK]
Common Mistakes:
MISTAKES
  • Assuming zero is allowed with > 0
  • Thinking database auto-fixes zero to 1
  • Believing insertion succeeds with warnings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes