Databases · Junior · Question 7 of 75
What does a CHECK constraint do?
CREATE TABLE products (
id bigint PRIMARY KEY,
price numeric NOT NULL CHECK (price >= 0)
);- 1Logs a warning but stores the row anyway
- ✓Correct answer: Rejects rows where the condition is false, here a negative price
- 3Checks the value only when you run
SELECT
Explanation
Constraints in the database protect data from every client: your API, scripts, admin tools. Validation only in application code can be bypassed.