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
13. Question

Instruction

Here's the exercise for you!

Exercise

A traveler asked us to help him modify the table where he keeps basic information about all his trips. The table has the following definition:

CREATE TABLE trip (
  id integer PRIMARY KEY,
  destination varchar(64),
  total_budget decimal(6, 2),
  budget_souvenirs decimal(6, 2),
  nights integer CHECK (nights > 0)
);

Your task is to:

  1. Add a constraint to ensure that budget_souvenirs is less than total_budget.
  2. Remove the constraint from the nights column. (He could take a day trip somewhere, with no overnight stays.)