In this recipe, you will learn how to drop a database in Hive.
Drop Database
statements drop the database and the objects inside that database. When a database is dropped, its directory is also deleted. The general format of dropping a database is as follows:
DROP (DATABASE|SCHEMA) [IF EXISTS] database_name [RESTRICT|CASCADE];
Where:
DATABASE|SCHEMA
: These are the same thing. These words can be used interchangeably.[IF EXISTS]
: This is an optional clause. If not used, an error is thrown when there is an attempt to drop a database that does not exist.[RESTRICT|CASCADE]
: This is an optional clause.RESTRICT
is used to restrict the database from getting dropped if there are one or more tables present in the database.RESTRICT
is the default behavior of the database.CASCADE
is used to drop all the tables present in the database before dropping the database.