Cassandra截断表

Cassandra截断表

TRUNCATE命令用于截断表。 如果您截断表,表的所有行将永久删除。

语法:

TRUNCATE <tablename>

示例:

我们有一个名为“student”的表具有以下数据(创建表并插入数据):

cqlsh:zyiz_ks> CREATE TABLE student(
             ...    student_id int PRIMARY KEY,
             ...    student_name text,
             ...    student_fees varint
             ...  );
cqlsh:zyiz_ks>
cqlsh:zyiz_ks> INSERT INTO student (student_id, student_fees, student_name)
             ... VALUES(1,5000, 'Maxsu');
cqlsh:zyiz_ks> INSERT INTO student (student_id, student_fees, student_name)
             ... VALUES(2,3000, 'Minsu');
cqlsh:zyiz_ks> INSERT INTO student (student_id, student_fees, student_name)
             ... VALUES(3, 2000, 'Modlee');
cqlsh:zyiz_ks>
cqlsh:zyiz_ks> select * from student;

 student_id | student_fees | student_name
------------+--------------+--------------
|         5000 |        Maxsu
|         3000 |        Minsu
|         2000 |       Modlee

(3 rows)
cqlsh:zyiz_ks>

现在,我们使用TRUNCATE命令:

TRUNCATE student;

现在表已经被截断了,您可以使用SELECT命令验证它。

SELECT * FROM student;

如下图所示 -

您可以看到表student现在被截断。