Bird
0
0

Given the table employees(id INT PRIMARY KEY, age INT CHECK (age >= 18)), what happens if you try to insert (1, 16)?

medium📝 query result Q4 of 15
SQL - Table Constraints
Given the table employees(id INT PRIMARY KEY, age INT CHECK (age >= 18)), what happens if you try to insert (1, 16)?
AThe insert succeeds but age is set to NULL
BThe insert succeeds because PRIMARY KEY is valid
CThe insert fails due to CHECK constraint violation
DThe insert fails due to PRIMARY KEY violation
Step-by-Step Solution
Solution:
  1. Step 1: Understand the CHECK constraint on age

    The CHECK constraint requires age to be 18 or older.
  2. Step 2: Analyze the insert values

    Inserting age 16 violates the CHECK condition, so the insert fails.
  3. Final Answer:

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

    CHECK constraint violation causes insert failure [OK]
Quick Trick: CHECK stops invalid data that breaks rules [OK]
Common Mistakes:
MISTAKES
  • Ignoring CHECK and assuming insert succeeds
  • Confusing PRIMARY KEY violation with CHECK violation
  • Assuming NULL is inserted automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes