Bird
0
0

You try to create a table with this statement:

medium📝 Debug Q14 of 15
SQL - Table Constraints
You try to create a table with this statement:
CREATE TABLE employees (
  id INT,
  salary INT CHECK salary > 0
);

But get a syntax error. What is the likely fix?
AAdd a semicolon after salary
BAdd parentheses around the CHECK condition: CHECK (salary > 0)
CChange salary to VARCHAR
DRemove the CHECK constraint entirely
Step-by-Step Solution
Solution:
  1. Step 1: Identify syntax for inline CHECK constraints

    Inline CHECK constraints require the condition to be inside parentheses.
  2. Step 2: Check the given statement

    The statement misses parentheses around salary > 0, causing syntax error.
  3. Final Answer:

    Add parentheses around the CHECK condition: CHECK (salary > 0) -> Option B
  4. Quick Check:

    Inline CHECK needs parentheses [OK]
Quick Trick: Always use parentheses around CHECK conditions [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses in inline CHECK
  • Changing data type unnecessarily
  • Ignoring syntax error details

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes