Summary -
In this topic, we described about the Drop Database in detail.
Drop database used to delete the database in the HIVE system. Before deleting the database, it also deletes the tables, views etc, everything on the database.
It deletes the corresponding *.db directory from HDFS. The database should be empty or should take a backup of the data or or move them to other databases before database can be dropped, to avoid losing any data.
Syntax -
DROP (DATABASE|SCHEMA) [IF EXISTS] database_name
[RESTRICT|CASCADE];
IF EXISTS, RESTRICT, CASCADE are all optional keywords and will be used on need basis. The database and schema are interchangeable. DATABASE or SCHEMA is same thing in behavior. DROP DATABASE was added in Hive 0.6.
Let us assume std_db is the database created by the user needs to dropped. The below syntax can be used to delete the database.
Hive> DROP DATABASE IF EXISTS std_db CASCADE;
CASCADE will be used to delete all table, view etc, before deleting the database.
Let us assume newsch is the schema created by the user to be dropped. The below syntax can delete the schema.
Hive> DROP SCHEME IF EXISTS newsch CASCADE;