May 26, 2021 impala
Impala's True Table statement is used to delete all records from an existing table.
You can also use the DROP TABLE command to delete a complete table, but it removes the full table structure from the database, and if you want to store some data, you will need to re-create the table.
The following is the syntax of the truncate table statement.
truncate table_name;
Suppose we have a table called customers in Impala, and if you verify its contents, you get the following results. T his means that the customers table contains six records.
[quickstart.cloudera:21000] > select * from customers; Query: select * from customers +----+----------+-----+-----------+--------+--------+ | id | name | age | address | salary | e_mail | +----+----------+-----+-----------+--------+--------+ | 1 | Ramesh | 32 | Ahmedabad | 20000 | NULL | | 2 | Khilan | 25 | Delhi | 15000 | NULL | | 3 | kaushik | 23 | Kota | 30000 | NULL | | 4 | Chaitali | 25 | Mumbai | 35000 | NULL | | 5 | Hardik | 27 | Bhopal | 40000 | NULL | | 6 | Komal | 22 | MP | 32000 | NULL | +----+----------+-----+-----------+--------+--------+
The following is an example of truncate statements to truncate tables in Impala. H ere we delete all records of the table named Customers.
[quickstart.cloudera:21000] > truncate customers;
When executing the above statement, Impala deletes all records for the specified table and displays the following message.
Query: truncate customers Fetched 0 row(s) in 0.37s
If you verify the contents of the customers table, after deleting the operation, you will get an empty row using the select statement, as shown below.
[quickstart.cloudera:21000] > select * from customers; Query: select * from customers Fetched 0 row(s) in 0.12s
Open the Impala query editor and type the truncate statement in it. T hen click the execute button, as shown in the screenshot below.
After the query/statement is executed, all records in the table are deleted.