Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
CHECK constraints with a simple condition
CHECK constraints with complex conditions
Adding CHECK constraints to existing tables
Summary
12. Summary

Instruction

Perfect! Time to wrap up this part with a quick summary:

  1. When creating a table, add a CHECK constraint on a single column with:
    CREATE TABLE video_game (
      id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
      ...
      hours integer CHECK (hours > 0),
      ...
    );
  2. To add a CHECK constraint on multiple columns, use:
    CREATE TABLE video_game (
      id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
      ...
      hours integer,
      price decimal(5, 2),
      CHECK (price/hours < 1.00)
    );
  3. To add a CHECK constraint to an existing table, use:
    ALTER TABLE video_game_ranking
    ADD CONSTRAINT video_game_rank_constraint CHECK (rank > 0);
  4. To remove a CHECK constraint from an existing table, use:
    ALTER TABLE video_game_ranking
    DROP CONSTRAINT video_game_ranking_award_count_check;

How about a short quiz now?

Exercise

Click Next exercise to continue.