Drop a table

Tables with the Data API are currently in public preview. Development is ongoing, and the features and functionality are subject to change. Hyper-Converged Database (HCD), and the use of such, is subject to the DataStax Preview Terms.

Deletes a table from a database, including all data stored in the table.

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

  • Python

  • TypeScript

  • Java

  • curl

Deletes the specified table from the database, including all data stored in the table.

Does not return anything.

Deletes the specified table from the database, including all data stored in the table.

Returns a promise that resolves once the operation completes.

Deletes the specified table from the database, including all data stored in the table.

Does not return anything.

Deletes the specified table from the database, including all data stored in the table.

If the command succeeds, the response indicates the success.

Example successful response:

{
  "status": {
    "ok": 1
  }
}

Parameters

  • Python

  • TypeScript

  • Java

  • curl

Use the drop_table method, which belongs to the astrapy.Database class.

Method signature
drop_table(
  name: str || Table,
  *,
  keyspace: str,
  if_exists: bool,
  table_admin_timeout_ms: int,
  request_timeout_ms: int,
  timeout_ms: int,
) -> None
Name Type Summary

name

str | Table

The name of the table to drop, or a Table instance corresponding to that table.

keyspace

str

Optional if you specified a keyspace when instantiating the Database object. The keyspace containing the table.

Default: The working keyspace for the database.

if_exists

bool

Optional. Whether the command should silently succeed even if a table with the given name does not exist in the keyspace and no table was dropped.

Default: false

table_admin_timeout_ms

int

Optional. A timeout, in milliseconds, for the underlying HTTP request. If not provided, the Database setting is used. This parameter is aliased as request_timeout_ms and timeout_ms for convenience.

Use the dropTable method, which belongs to the Db class.

Method signature
async dropTable(
  name: string,
  options?: {
    ifExists?: boolean,
    keyspace?: string,
    timeout?: number | TimeoutDescriptor,
  }
): void
Name Type Summary

name

string

The name of the table to drop.

options

DropTableOptions

The options for this operation. See Properties of options for more details.

Properties of options
Name Type Summary

if_exists

boolean

Optional. Whether the command should silently succeed even if a table with the given name does not exist in the keyspace and no table was dropped.

Default: false

keyspace

string

Optional if you specified a keyspace when instantiating the Database object. The keyspace containing the table.

Default: The working keyspace for the database.

timeout

number | TimeoutDescriptor

The timeout(s) to apply to HTTP request(s) originating from this method.

Use the dropTable method, which belongs to the com.datastax.astra.client.databases.Database class.

Method signature
void dropTable(String tableName)
void dropTable(
  String tableName,
  DropTableOptions dropTableOptions
)
Name Type Summary

name

String

The name of the table to drop.

options

DropTableOptions

Optional. The options for this operation. See Methods of DropTableOptions for more details.

Methods of DropTableOptions
Method Parameters Summary

ifExists()

boolean

Optional. Whether the command should silently succeed even if a table with the given name does not exist in the keyspace and no table was dropped.

Default: false

keyspace()

String

Optional if you specified a keyspace when instantiating the Database object. The keyspace containing the table.

Default: The working keyspace for the database.

timeout()

long | Duration

Optional. The timeout(s) to apply to HTTP request(s) originating from this method.

Use the dropTable command.

Command signature
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "dropTable": {
      "name": "TABLE_NAME"
  }
}'
Name Type Summary

name

string

The name of the table to drop.

Examples

The following examples demonstrate how to drop a table.

Drop a table by name

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment

# Get a database
client = DataAPIClient(environment=Environment.HCD)
database = client.get_database(
    "API_ENDPOINT",
    token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
)

# Drop a table
database.drop_table("TABLE_NAME", keyspace="KEYSPACE_NAME")
import {
  DataAPIClient,
  UsernamePasswordTokenProvider,
} from "@datastax/astra-db-ts";

// Get a database
const client = new DataAPIClient({ environment: "hcd" });
const database = client.db("API_ENDPOINT", {
  token: new UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
});

// Drop a table
(async function () {
  await database.dropTable("TABLE_NAME", { keyspace: "KEYSPACE_NAME" });
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.commands.options.DropTableOptions;

public class Example {

  public static void main(String[] args) {
    // Get a database
    DataAPIClient client = DataAPIClients.clientHCD("USERNAME", "PASSWORD");
    Database database = client.getDatabase("API_ENDPOINT", "KEYSPACE_NAME");

    // Drop a table
    database.dropTable("TABLE_NAME", new DropTableOptions());
  }
}
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "dropTable": {
      "name": "TABLE_NAME"
  }
}'

Drop a table through a Table object

If you get a Table object through one of the clients, you can drop the table through that object.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment

# Get an existing table
client = DataAPIClient(environment=Environment.HCD)
database = client.get_database(
    "API_ENDPOINT",
    token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
)
table = database.get_table("TABLE_NAME", keyspace="KEYSPACE_NAME")

# Drop the table
table.drop()
import {
  DataAPIClient,
  UsernamePasswordTokenProvider,
} from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient({ environment: "hcd" });
const database = client.db("API_ENDPOINT", {
  token: new UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
});
const table = database.table("TABLE_NAME", {
  keyspace: "KEYSPACE_NAME",
});

// Drop the table
(async function () {
  await table.drop();
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    DataAPIClient client = DataAPIClients.clientHCD("USERNAME", "PASSWORD");
    Database database = client.getDatabase("API_ENDPOINT", "KEYSPACE_NAME");
    Table<Row> table = database.getTable("TABLE_NAME");

    // Drop the table
    table.drop();
  }
}

Table objects do not apply to HTTP.

Drop a table only if the table exists

Use this option to silently do nothing if a table with the specified name does not exist.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment

# Get a database
client = DataAPIClient(environment=Environment.HCD)
database = client.get_database(
    "API_ENDPOINT",
    token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
)

# Drop a table
database.drop_table("TABLE_NAME", if_exists=True, keyspace="KEYSPACE_NAME")
import {
  DataAPIClient,
  UsernamePasswordTokenProvider,
} from "@datastax/astra-db-ts";

// Get a database
const client = new DataAPIClient({ environment: "hcd" });
const database = client.db("API_ENDPOINT", {
  token: new UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
});

// Drop a table
(async function () {
  await database.dropTable("TABLE_NAME", {
    ifExists: true,
    keyspace: "KEYSPACE_NAME",
  });
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.commands.options.DropTableOptions;

public class Example {

  public static void main(String[] args) {
    // Get a database
    DataAPIClient client = DataAPIClients.clientHCD("USERNAME", "PASSWORD");
    Database database = client.getDatabase("API_ENDPOINT", "KEYSPACE_NAME");

    // Drop a table
    DropTableOptions options = new DropTableOptions().ifExists(true);
    database.dropTable("TABLE_NAME", options);
  }
}

This option has no literal equivalent in HTTP. Instead, you can list the table names to see if a table with the name already exists.

Client reference

  • Python

  • TypeScript

  • Java

  • curl

For more information, see the client reference.

For more information, see the client reference.

For more information, see the client reference.

Client reference documentation is not applicable for HTTP.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax, an IBM Company | 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: +1 (650) 389-6000, info@datastax.com