Summary -
In this topic, we described about the Drop Table in detail.
Drop table removes/deleted the table. Drop table also removes the underlying HDFS data files for internal tables. Drop table can’t able to delete underlying HDFS data files for external tables.
By default, it removes the associated HDFS directory and data files for the table. The files can’t be deleted if the table was created with the EXTERNAL clause or there is no HDFS location available.
Syntax -
DROP TABLE [IF EXISTS] [db_name.]table_name
The optional IF EXISTS clause makes the statement succeed whether or not the table exists. If the table does exist, it is dropped and if it does not exist, the statement has no effect.
Example -
Assume we have a requirement to create student information with the columns student number, name, class, grade for a school.
Std No | Std Name | Std Class | Std Grade |
---|---|---|---|
1 | Pawan | 10 | A |
2 | Srinivas | 10 | A |
3 | Sridhar | 10 | A |
4 | Kumar | 10 | B |
std_details table can be dropped by using the below DROP TABLE command.
Hive> DROP TABLE IF EXISTS std_db.std_details
On the successful completion of the above statement, the table std_details will be dropped.