DROP DATABASE Statement DROP DATABASE

DROP DATABASE statement Removes a database from the system. The physical operations involve removing the metadata for the database from the metastore, and deleting the corresponding *.db directory from HDFS.

DROP (DATABASE|SCHEMA) [IF EXISTS] database_name [RESTRICT | CASCADE];

By default, the database must be empty before it can be dropped, to avoid losing any data.

In and higher, you can include the CASCADE clause to make Impala drop all tables and other objects in the database before dropping the database itself. The RESTRICT clause enforces the original requirement that the database be empty before being dropped. Because the RESTRICT behavior is still the default, this clause is optional.

The automatic dropping resulting from the CASCADE clause follows the same rules as the corresponding DROP TABLE, DROP VIEW, and DROP FUNCTION statements. In particular, the HDFS directories and data files for any external tables are left behind when the tables are removed.

When you do not use the CASCADE clause, drop or move all the objects inside the database manually before dropping the database itself:

You cannot drop the current database, that is, the database your session connected to either through the USE statement or the -d option of impala-shell. Issue a USE statement to switch to a different database first. Because the default database is always available, issuing USE default is a convenient way to leave the current database before dropping it.

When you drop a database in Impala, the database can no longer be used by Hive.

See for examples covering CREATE DATABASE, USE, and DROP DATABASE.

The user ID that the impalad daemon runs under, typically the impala user, must have write permission for the directory associated with the database.

, , , ,