Reputation: 61
I am facing a problem with deleting all the records from a table.
I can use Truncate table. But truncate would create a snapshot of the data which would be a wastage of storage space in my scenario.
Also truncate would fail if any of the nodes are down.
So I would like to know if there is any way to delete all the records in a table without creating a snapshot that works if a node is down.
Upvotes: 5
Views: 4060
Reputation: 1661
To alter the behavior of creating a snapshot before truncate you can change your cassandra.yaml
# Whether or not a snapshot is taken of the data before keyspace truncation
# or dropping of column families. The STRONGLY advised default of true
# should be used to provide data safety. If you set this flag to false, you will
# lose data on truncation or drop.
auto_snapshot: true
This value is set to true by default. If you don't want this, you can simply set it to false. Just a little warning here, this flag is to make sure that after a drop or a truncate your data is not lost without a second thought. So think really carefully if you really want to disable that feature.
Upvotes: 7
Reputation: 420
simple use like this
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
public class Truncate_Table {
public static void main(String args[]){
//Query
String query = "Truncate student;";
//Creating Cluster object
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
//Creating Session object
Session session = cluster.connect("tp");
//Executing the query
session.execute(query);
System.out.println("Table truncated");
}
}
i think this will help you
Upvotes: -3