How to truncate a table in Cassandra using CQLSH

Syntax for truncating a table/columnfamily is :

TRUNCATE <TABLE_NAME | COLUMN_FAMILY_NAME>

Using this command will delete all the rows from the table/columnfamily.

Let’s say the data in our table is:

select * from users;

Output:

user_id | user_email | user_name | user_pwd
---------+--------------+-----------+----------
1 | aa@gmail.com | user1 | pwd1

To truncate all the data from the table use:

truncate users;

Verify the output.

select * from users;

Output:

user_id | user_email | user_name | user_pwd
---------+------------+-----------+----------
(0 rows)

Leave a Reply

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