Bird
0
0

Given the table creation:

medium📝 query result Q13 of 15
SQL - Table Constraints
Given the table creation:
CREATE TABLE products (
  id INT,
  price DECIMAL(5,2),
  CONSTRAINT chk_price CHECK (price >= 0)
);

What happens if you run:
INSERT INTO products (id, price) VALUES (1, -10.00);
AThe row is inserted successfully
BThe price is automatically set to 0
CThe insert fails due to CHECK constraint violation
DThe insert causes a syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the CHECK constraint on price

    The constraint requires price to be greater than or equal to 0.
  2. Step 2: Analyze the insert statement

    The insert tries to add price = -10.00, which violates the CHECK condition.
  3. Final Answer:

    The insert fails due to CHECK constraint violation -> Option C
  4. Quick Check:

    price < 0 violates CHECK = insert fails [OK]
Quick Trick: CHECK rejects rows violating the condition [OK]
Common Mistakes:
MISTAKES
  • Assuming negative values are accepted
  • Thinking CHECK auto-corrects values
  • Confusing CHECK violation with syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes