Truncating Tables in Hive

#1

Let us understand how to truncate tables.

  • TRUNCATE works only for managed tables. Only data will be deleted, structure will be retained.
  • Launch hive (we cannot use database as database is dropped)
CREATE DATABASE training_retail;
CREATE TABLE orders (
  order_id INT,
  order_date STRING,
  order_customer_id INT,
  order_status STRING
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

LOAD DATA LOCAL INPATH '/data/retail_db/orders'
  INTO TABLE orders;
SELECT * FROM orders LIMIT 10;

TRUNCATE TABLE orders;

Practice hive on state of the art Big Data cluster - https://labs.itversity.com
You can sign up for our courses on Udemy using $10 coupons - Udemy Coupons - Big Data Courses


0 Likes