Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Deleting views
3. DROP VIEW – dependencies
Deleting and modifying tables with views
Modifying views
Summary

Instruction

Good job! Now, let's look at another example that's a bit more complicated. We have the same table and two views:

CREATE TABLE gym (
  id integer PRIMARY KEY,
  name varchar(32),
  city varchar(32),
  monthly_fee decimal(5, 2),
  max_capacity integer
);
CREATE VIEW big_gyms_london AS
SELECT id, name, max_capacity
FROM gym
WHERE city = 'London'
  AND max_capacity > 50;
CREATE VIEW big_gyms_london_avg AS
SELECT AVG(max_capacity)
FROM big_gyms_london;

The view big_gyms_london is dependent on the gym table, but the big_gyms_london_avg view is dependent on the big_gyms_london view. What happens if we try to delete the big_gyms_london view?

Exercise

Run the template query, which attempts to delete the big_gyms_london view.

As you can see, the query failed.