Does drop table
command in hive
also drop partitions?
I just want to know that or we have to use alter table table_name drop partition()
command for this?
DROP TABLE
statement always drops partitions metadata for both MANAGED
and EXTERNAL
tables because partitions can not exist without table. But for EXTERNAL
tables it does not drop data in the filesystem.
If table is MANAGED
, then DROP TABLE
will delete table and partitions metadata and data in table location as well, all the table location including partition sub-folders.
If the table is EXTERNAL
, it will drop only table definition in metadata and partition definitions, table location with data, including all partition folders will remain as is, and you can again create table on top of the same location and recover partitions.
The same is applicable for DROP PARTITION
: if table is MANAGED
, it will remove partition metadata along with partition sub-folder. And if table is EXTERNAL
, partition sub-folder with data will remain, only partition metadata will be deleted.
So, for MANAGED
tables, you do not need to delete data after dropping table or partition.
See also DROP TABLE and DROP PARTITION manual for more details.