DROP VIEW Statement

Removes the specified view, which was originally created by the CREATE VIEW statement. Because a view is purely a logical construct (an alias for a query) with no physical data behind it, DROP VIEW only involves changes to metadata in the metastore database, not any data files in HDFS.

Syntax:

  1. DROP VIEW [IF EXISTS] [db_name.]view_name

Statement type: DDL

Cancellation: Cannot be cancelled.

HDFS permissions: This statement does not touch any HDFS files or directories, therefore no HDFS permissions are required.

Examples:

The following example creates a series of views and then drops them. These examples illustrate how views are associated with a particular database, and both the view definitions and the view names for CREATE VIEW and DROP VIEW can refer to a view in the current database or a fully qualified view name.

  1. -- Create and drop a view in the current database.
  2. CREATE VIEW few_rows_from_t1 AS SELECT * FROM t1 LIMIT 10;
  3. DROP VIEW few_rows_from_t1;
  4. -- Create and drop a view referencing a table in a different database.
  5. CREATE VIEW table_from_other_db AS SELECT x FROM db1.foo WHERE x IS NOT NULL;
  6. DROP VIEW table_from_other_db;
  7. USE db1;
  8. -- Create a view in a different database.
  9. CREATE VIEW db2.v1 AS SELECT * FROM db2.foo;
  10. -- Switch into the other database and drop the view.
  11. USE db2;
  12. DROP VIEW v1;
  13. USE db1;
  14. -- Create a view in a different database.
  15. CREATE VIEW db2.v1 AS SELECT * FROM db2.foo;
  16. -- Drop a view in the other database.
  17. DROP VIEW db2.v1;

Related information:

Overview of Impala Views, CREATE VIEW Statement, ALTER VIEW Statement

Parent topic: Impala SQL Statements