Delete a row (C#)

Finds a single row in a table using filter clauses, and then deletes that row.

Deleting rows produces tombstones. Excessive tombstones can impact query performance.

For general information about working with tables and rows, see About tables with the Data API (C#).

Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart.

Result

Deletes a row that matches the specified parameters. If no rows match the specified parameters, this method does not delete any rows.

Does not return anything.

Parameters

Use the DeleteOneAsync method, which belongs to the Table class. You can also use DeleteOne, which is the synchronous version of the method.

Method signature
public Task DeleteOneAsync(
  TableFilter<T> filter, TableDeleteOneOptions<T> options = null
);

For best performance, filter and sort on indexed columns, partition keys, and clustering keys.

Filtering on non-indexed columns is inefficient and resource-intensive, especially for large datasets. With the Data API clients, such operations can hit the client timeout limit before the underlying HTTP operation is complete. If you filter on non-indexed columns, the Data API will give a warning.

An empty filter or omitted filter may also result in an inefficient and long-running operation.

Additionally, the Data API can perform in-memory sorting, depending on the columns you sort on, the table’s partitioning structure, and whether the sorted columns are indexed. In-memory sorts can have performance implications.

Name Type Summary

filter

TableFilter

Describes the full primary key of the row to delete.

For this method, the filter can only use the $eq operator and columns in the primary key.

options

TableDeleteOneOptions

Optional. General API options for this operation, including the timeout. For more information and examples, see Customize API interaction.

Examples

The following examples demonstrate how to delete a row in a table.

Delete a row by primary key

You can filter by primary key to find and delete a row. The filter must describe the full primary key and cannot include any other columns.

using System.Text.Json;
using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Core;
using DataStax.AstraDB.DataApi.Tables;

namespace Examples;

public class Program
{
  static async Task Main()
  {
    // Get an existing table
    var client = new DataAPIClient(
      new CommandOptions() { Destination = DataAPIDestination.HCD }
    );

    var database = client.GetDatabase(
      "API_ENDPOINT",
      DataAPIClient.UsernamePasswordTokenProvider(
        "USERNAME",
        "PASSWORD"
      ),
      "KEYSPACE_NAME"
    );

    var table = database.GetTable("TABLE_NAME");

    // Delete a row
    var filterBuilder = Builders<Row>.TableFilter;
    var filter = filterBuilder.And(
      filterBuilder.Eq("title", "Hidden Shadows of the Past"),
      filterBuilder.Eq("author", "John Anthony")
    );

    await table.DeleteOneAsync(filter);
  }
}

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM