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

Instruction

Let's get started then. Suppose we have the following table and a view based on it:

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;

At some point we decide that we no longer need the view. What can we do then? Take a look:

DROP VIEW big_gyms_london;

As you can see, deleting a view in SQL is very simple.

Exercise

You're given a table with courses offered at a university:

CREATE TABLE course (
  id integer PRIMARY KEY,
  name varchar(128),
  lecturer varchar(128),
  ects_points integer,
  max_students integer,
  has_exam boolean
);

There's also a view which selects courses run by professor John Smith:

CREATE VIEW courses_prof_smith AS
SELECT id, name, max_students, has_exam
FROM course
WHERE lecturer = 'John Smith';

Your task is to drop this view.