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
11. Removing CHECK constraints from existing tables
Summary

Instruction

Great! What about deleting a constraint? Let's go back to the video_game_ranking table:

CREATE TABLE video_game_ranking (
  game_id integer,
  user_rating decimal(4, 1),
  expert_rating decimal(4, 1),
  rank integer,
  award_count integer CHECK (award_count > 0)
);

Let's say we want to delete the constraint from the award_count column. Here's how we'd do it:

ALTER TABLE video_game_ranking
DROP CONSTRAINT video_game_ranking_award_count_check;

Again, we're using code which should be familiar to you – you can delete primary/foreign keys and the UNIQUE constraints in the same way. The default naming convention for a CHECK constraint in PostgreSQL is table_name + _ + column_name(s) + _ + check. In our example, the check was made on the award_count column, so the constraint was named video_game_ranking_award_count_check.

Exercise

You are again given the train_connection table:

CREATE TABLE train_connection (
  id integer PRIMARY KEY,
  city_from varchar(32),
  city_to varchar(32),
  distance_miles integer,
  basic_price decimal(5, 2) CHECK (basic_price > 0.0)
);

It turns out that some train connections are completely free of charge. Your task is to remove the constraint on the basic_price column.