Table cleaning

Sometimes, we may need to clean up the table, either by deleting only the records or the table along with the records. There are two statements in HQL to do such cleaning. One is the DROP TABLE statement, and the other is TRUNCATE TABLE. The drop-table statement on an internal table removes the table completely and moves data to .trash in the current user directory, if the trash setting is configured. The drop-table statement on an external table will only remove the table definition, but keeps data:

> DROP TABLE IF EXISTS empty_ctas_employee;No rows affected (0.283 seconds)

On the other hand, the truncate table statement only removes data from the table. The table still exists, but is empty. Note, truncate table can only apply ...

Get Apache Hive Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.