Summary: in this tutorial, you will learn how to use the Db2 DROP VIEW
statement to remove a view from the database.
Introduction to DROP VIEW statement
To remove a view from the database, you use the DROP VIEW
statement:
DROP VIEW view_name;
Code language: SQL (Structured Query Language) (sql)
In this syntax, you just need to specify the name of the view that you want to delete in the DROP VIEW
clause.
Once you delete the view, Db2 will mark all views that depend on the deleted view inoperative.
Db2 doesn’t allow you to delete multiple views using a single DROP VIEW
statement. Therefore, you have to execute multiple DROP VIEW
statements to delete multiple views.
In other database systems, you may find that they have DROP VIEW IF EXISTS
statement to conditionally delete a view only if it exists. However, Db2 doesn’t support IF EXISTS
clause.
DB2 DROP VIEW example
We’ll use the book_details
view created in the CREATE VIEW
tutorial for the demonstration.
The following statement uses the DROP VIEW
statement to remove the view book_details
:
DROP VIEW book_details;
Code language: SQL (Structured Query Language) (sql)
In this tutorial, you’ve learned how to use the DROP VIEW
statement to delete a view from the database.