Tables, Keys & Constraints · Question 7 · Easy

What happens when the INSERT with a price of -50 runs?

CREATE TABLE Product (
  id INT PRIMARY KEY,
  name VARCHAR(20),
  price INT CHECK (price > 0)
);
INSERT INTO Product VALUES (1, 'Diary', -50);
  1. It fails, because -50 breaks the CHECK (price > 0) rule
  2. It succeeds, and price is stored as -50
  3. It succeeds, and price is stored as 0
  4. It succeeds, and price is stored as 50
Answer and explanation

Answer: A. It fails, because -50 breaks the CHECK (price > 0) rule

Explanation: A CHECK constraint is tested for every inserted or updated row. -50 > 0 is false, so the row is rejected; the database does not adjust the value for you.

Previous: Which statement can remove only those rows of a table that satisfy a… · Next: In PostgreSQL, MySQL and SQLite, which follow the SQL standard on this point…

Practise tables, keys & constraints

Try a fresh set of tables, keys & constraints questions with an explanation after every answer, free and without signing up: Tables, Keys & Constraints practice. Or sit a full placement mock test.

More tables, keys & constraints questions

More sql practice

DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge