|The Cassandra 1.2 documentation is transitioning to a new format! Please use the new Cassandra 1.2 documentation instead.||Back to Table of Contents All Documents List|
To remove data, you can set column values for automatic removal using the TTL (time-to-expire) table attribute. You can also drop a table or keyspace, and delete keyspace column metadata.
Both the INSERT and UPDATE commands support setting a time for data in a column to expire. The expiration time (TTL) is set using CQL. The following example first shows an INSERT statement that sets a password column in the users table to expire in 86400 seconds, or one day. If you wanted to extend the expiration period to five days, use the UPDATE command as shown in the second example:
cqlsh:demodb> INSERT INTO users (user_name, password) VALUES ('cbrown', 'ch@ngem4a') USING TTL 86400; cqlsh:demodb> UPDATE users USING TTL 432000 SET 'password' = 'ch@ngem4a' WHERE user_name = 'cbrown';
Using cqlsh commands, you can drop a keyspace or table. This example shows the commands that drops the users table and then, the demodb keyspace:
cqlsh:demodb> DROP TABLE users; cqlsh:demodb> DROP KEYSPACE demodb;
CQL provides the DELETE command to delete a column or row. This example deletes user jsmith's session token column, and then deletes jsmith's entire row.
cqlsh:demodb> DELETE session_token FROM users where pk = 'jsmith'; cqlsh:demodb> DELETE FROM users where pk = 'jsmith';
Deleted values are removed completely by the first compaction following deletion.