How to use Hive TRUNCATE ?

4 comments

Difference between DELETE, TRUNCATE and DROP

  • DELETE : used to delete particular row with where condition and you can all delete all the rows from the given table.
  • TRUNCATE: used to truncate all the rows, which can not even be restored at all, this actions deletes data in Hive meta store.
  • DROP: it drops the table along with the data associated with Hive Meta store.

Let us practice all the above mentioned one by one.

TRUNCATE

If we want to remove particular row from Hive meta store Table we use DELETE but if we want to delete all the rows from HIVE table we can use TRUNCATE.

Note:

  • if you had created a TABLE with EXTERNAL keyword then you can NOT remove all the rows because all data resides outside of Hive Meta store.
  • Truncate also removes all the values inside table.

before using TRUNCATE, let us see whether we have values inside table:
for example:

Let us now apply TRUNCATE:

now if we try to select rows, we will not see anything.

 

 

 

 

Leave a comment

Your email address will not be published. Required fields are marked *

4 thoughts on “How to use Hive TRUNCATE ?”