DELETE命令用於從Cassandra表中刪除數據。 您可以使用此命令刪除完整的表或選定的行。
語法:
DELETE FROM <identifier> WHERE <condition>;
下麵舉個例子來演示如何從Cassandra表中刪除數據。 我們有一個名為“student”的表其中列(student_id,student_fees, student_name),這個表中具有以下數據。
cqlsh:zaixian_ks> SELECT * FROM student;
 student_id | student_fees | student_name
------------+--------------+--------------
          1 |         5000 |        Maxsu
          2 |        10000 |      XunWang
          3 |         2000 |       Modlee
(3 rows)
cqlsh:zaixian_ks>
刪除整行
要刪除student_id為3的整行記錄,請使用以下命令:
DELETE FROM student WHERE student_id=3;
在執行上面語句之後,student_id為 3 的行記錄已被刪除。 您可以使用SELECT命令驗證它。
cqlsh:zaixian_ks> SELECT * FROM student;
 student_id | student_fees | student_name
------------+--------------+--------------
          1 |         5000 |        Maxsu
          2 |        10000 |      XunWang
          3 |         2000 |       Modlee
(3 rows)
cqlsh:zaixian_ks> DELETE FROM student WHERE student_id=3;
cqlsh:zaixian_ks> SELECT * FROM student;
 student_id | student_fees | student_name
------------+--------------+--------------
          1 |         5000 |        Maxsu
          2 |        10000 |      XunWang
(2 rows)
cqlsh:zaixian_ks>
刪除一個特定的列名
示例:
刪除student_id為2的記錄中的student_fees列中的值。
DELETE student_fees FROM student WHERE student_id=2;
現在刪除 您可以驗證:
cqlsh:zaixian_ks> SELECT * FROM student;
 student_id | student_fees | student_name
------------+--------------+--------------
          1 |         5000 |        Maxsu
          2 |        10000 |      XunWang
(2 rows)
cqlsh:zaixian_ks> DELETE student_fees FROM student WHERE student_id=2;
cqlsh:zaixian_ks> SELECT * FROM student;
 student_id | student_fees | student_name
------------+--------------+--------------
          1 |         5000 |        Maxsu
          2 |         null |      XunWang
(2 rows)
cqlsh:zaixian_ks>
					
						上一篇:
								Cassandra更新數據
												下一篇:
								Cassandra集合
					
					