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

Instruction

As you can see, the query failed. We've run into the same problem as the one we had with dependent views – we can't delete a table if there are any objects (such as views) dependent on it. As you may guess, we can add the CASCADE option to delete the table:

DROP TABLE gym CASCADE;

The instruction above will delete the table gym and all its dependent objects, including views.

Exercise

This time, we've prepared the course table and a view dependent on it:

CREATE TABLE course (
  id integer PRIMARY KEY,
  name varchar(128),
  lecturer varchar(128),
  ects_points integer,
  max_students integer,
  has_exam boolean
);
CREATE VIEW courses_prof_smith AS
SELECT id, name, max_students, has_exam
FROM course
WHERE lecturer = 'John Smith';

Your task is to get rid of the course table.