DROP VIEW

Description

DROP VIEW removes the metadata associated with a specified view from the catalog.

Syntax

  1. DROP VIEW [ IF EXISTS ] view_identifier

Parameter

  • IF EXISTS

    If specified, no exception is thrown when the view does not exist.

  • view_identifier

    Specifies the view name to be dropped. The view name may be optionally qualified with a database name.

    Syntax: [ database_name. ] view_name

Examples

  1. -- Assumes a view named `employeeView` exists.
  2. DROP VIEW employeeView;
  3. -- Assumes a view named `employeeView` exists in the `userdb` database
  4. DROP VIEW userdb.employeeView;
  5. -- Assumes a view named `employeeView` does not exist.
  6. -- Throws exception
  7. DROP VIEW employeeView;
  8. Error: org.apache.spark.sql.AnalysisException: Table or view not found: employeeView;
  9. (state=,code=0)
  10. -- Assumes a view named `employeeView` does not exist,Try with IF EXISTS
  11. -- this time it will not throw exception
  12. DROP VIEW IF EXISTS employeeView;