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)
);

Explanation

Constraints in the database protect data from every client: your API, scripts, admin tools. Validation only in application code can be bypassed.

Further reading

Problem with a question

Databases · Junior · question 7

Test yourself

Take the Databases · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz