DROP VIEW
Applies to: Databricks SQL
Databricks Runtime
Removes the metadata associated with a specified view from the catalog.
To drop a view you must have the MANAGE privilege on the view, be its owner, or the owner of the schema, catalog, or metastore the view resides in.
When you drop a Unity Catalog metric view, Databricks also deletes the relationships (Beta) declared on it. Relationships from other metric views to the dropped metric view no longer appear in DESCRIBE TABLE EXTENDED or INFORMATION_SCHEMA.TABLE_CONSTRAINTS.
Syntax
DROP [ MATERIALIZED ] VIEW [ IF EXISTS ] view_name
Parameter
-
IF EXISTS
If specified, no TABLE_OR_VIEW_NOT_FOUND error is thrown when the view does not exist.
-
The name of the view to be dropped. If the view cannot be found Databricks raises a TABLE_OR_VIEW_NOT_FOUND error. If the relation found is not a view Databricks raises a WRONG_COMMAND_FOR_OBJECT_TYPE error.
Examples
-- Assumes a view named `employeeView` exists.
> DROP VIEW employeeView;
-- Assumes a view named `employeeView` exists in the `usersc` schema
> DROP VIEW usersc.employeeView;
-- Assumes a view named `employeeView` does not exist.
-- Throws TABLE_OR_VIEW_NOT_FOUND
> DROP VIEW employeeView;
[TABLE_OR_VIEW_NOT_FOUND]
-- Assumes a materialized view named `employeeView` exists.
> DROP MATERIALIZED VIEW employeeView
-- Assumes a view named `employeeView` does not exist. Try with IF EXISTS
-- this time it will not throw exception
> DROP VIEW IF EXISTS employeeView;