Delete data with SQL
Use Tablestore SDK for Java to execute DELETE statements and delete a single row from a data table for which local transactions are disabled.
Prerequisites
Install the Tablestore SDK for Java and initialize a client.
Use Tablestore SDK for Java 5.17.11 or later.
Create a mapping table for the data table from which you want to delete data, and make sure that local transactions are disabled for the data table.
If you use a RAM user, grant the
SQL_DMLpermission to the RAM user.
Description
Call the sqlQuery method to execute a DELETE statement and delete a single row. In the WHERE clause, use equality conditions to specify all primary key columns.
SQLQueryResponse sqlQuery(SQLQueryRequest request)
The following example deletes the row whose primary key values are 1 and row1 from the example_table data table.
String query = "DELETE FROM example_table "
+ "WHERE tenant_id = 1 AND pk = 'row1'";
SQLQueryRequest request = new SQLQueryRequest(query);
SQLQueryResponse response = client.sqlQuery(request);
System.out.println("Affected rows: " + response.getAffectedRows());
Parameters
SQLQueryRequest contains the following parameter.
|
Name |
Type |
Description |
|
query (required) |
String |
The |
Response
SQLQueryResponse contains the following fields related to the delete result.
|
Field |
Type |
Description |
|
|
long |
Call |
|
|
Map<String, ConsumedCapacity> |
Call |
|
|
SQLStatementType |
Call |