CQL DELETE Data

To delete data from a table in Cassandra, the DELETE command is used. Syntax:

DELETE FROM <identifier> WHERE <condition>;

Example 1: Delete an entire row. Employees table:

id	name	salary
1	Adi	50000
2	Bruno	30000
3	Chris	60000
4	Davis	20000
5	Eliza	15000

Query:

DELETE FROM employees WHERE id = 4;

Explanation: In the above example, we are deleting the row, where the value of ID is 4. Verify it by using the below command. SELECT * FROM employees;

Output:

id	name	salary
1	Adi	50000
2	Bruno	30000
3	Chris	60000
5	Eliza	15000

Example 2: Delete a specific value. Employees table:

id	name	salary
1	Adi	50000
2	Bruno	30000
3	Chris	60000
4	Davis	20000
5	Eliza	15000

Query:

DELETE salary FROM employees WHERE ID = 3;

Explanation: In the above example, we are deleting the value of the ‘salary’ column, where the value of ID is 3. Verify it by using the below command. SELECT * FROM employees;

Output:

id	name	salary
1	Adi	50000
2	Bruno	30000
3	Chris	null
4	Davis	20000
5	Eliza	15000
Please follow and like us:
Content Protection by DMCA.com