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. Astra DB Serverless, 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.

Method signature

  • Python

  • TypeScript

  • Java

  • curl

The following method belongs to the astrapy.Database class.

drop_table(
  name: str,
  *,
  keyspace: str,
  if_exists: bool,
  table_admin_timeout_ms: int,
  request_timeout_ms: int,
  timeout_ms: int,
) -> None

The following method belongs to the Db class.

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

The following methods belong to the com.datastax.astra.client.databases.Database class.

void dropTable(String tableName)
void dropTable(
  String tableName,
  DropTableOptions dropTableOptions
)
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "dropTable": {
      "name": "TABLE_NAME"
  }
}'

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 response:

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

Parameters

  • Python

  • TypeScript

  • Java

  • curl

Name Type Summary

name_or_table

str | Table

Either the name of a table or a Table instance.

if_exists

bool

If True, and the specified table doesn’t exist in the keyspace, then the command succeeds and silently does nothing. In this case, no actual table deletion occurs.

If False (default), an error occurs if a table with the specified name does not exist in the keyspace.

table_admin_timeout_ms

int

A timeout, in milliseconds, for the underlying schema-changing HTTP request. If not provided, the Database defaults apply. This parameter is aliased as request_timeout_ms and timeout_ms for convenience.

Name Type Summary

name

string

The name of the table to drop, if dropping through a Db instance.

option?

DropTableOptions

The options for this operation

Options (DropTableOptions):

Name Type Summary

ifExists?

boolean

If true, and the specified table doesn’t exist in the keyspace, then the command succeeds and silently does nothing. In this case, no actual table deletion occurs.

If false (default), an error occurs if a table with the specified name does not exist in the keyspace.

keyspace?

string

If dropping through a Db instance, specify the keyspace containing the table that you want to drop. If unspecified, the database’s working keyspace is used.

timeout?

number | TimeoutDescriptor

The client-side timeout for this operation.

Name Type Summary

name

str

The name of the table to drop, if dropping through a database instance.

options

DropTableOptions

Specialization of the operation:

  • ifExists(): If true, and the specified table doesn’t exist in the keyspace, then the command succeeds and silently does nothing. In this case, no actual table deletion occurs.

    If false (default), an error occurs if a table with the specified name does not exist in the keyspace.

  • keyspace() If dropping through a database instance, specify the keyspace containing the table that you want to drop. If unspecified, the database’s working keyspace is used.

  • timeout: The client-side timeout for this operation.

Name Type Summary

dropTable

command

The Data API command to delete a table in a Serverless (Vector) database. It acts as a container for all the attributes and settings required to delete the table.

name

string

The name of the table to delete.

Examples

The following examples demonstrate how to drop a table.

Drop a table by name

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient

# Get a database
client = DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
database = client.get_database("ASTRA_DB_API_ENDPOINT")

# Drop a table
database.drop_table("example_table")
import { DataAPIClient } from '@datastax/astra-db-ts';

// Get a database
const client = new DataAPIClient('ASTRA_DB_APPLICATION_TOKEN');
const database = client.db('ASTRA_DB_API_ENDPOINT');

// Drop a table
(async function () {
  await database.dropTable("example_table");
})();
package com.example;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.databases.Database;

public class DropTable {

    public static void main(String[] args) {
        // Get a database
        Database database = new DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
            .getDatabase("ASTRA_DB_API_ENDPOINT");

        // Drop a table
        database.dropTable("example_table");
    }
}
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/ASTRA_DB_TABLE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "dropTable": {
      "name": "example_table"
  }
}'

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

# Get an existing table
client = DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
database = client.get_database("ASTRA_DB_API_ENDPOINT")
table = database.get_table("TABLE_NAME")

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

// Get an existing table
const client = new DataAPIClient('ASTRA_DB_APPLICATION_TOKEN');
const database = client.db('ASTRA_DB_API_ENDPOINT');
const table = database.table('TABLE_NAME');

// Drop the table
(async function () {
  await table.drop();
})();
package com.example;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.databases.Database;

public class DropTable {

    public static void main(String[] args) {
        // Get an existing table
        Table<Row> table = new DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
            .getDatabase("ASTRA_DB_API_ENDPOINT")
            .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

# Get a database
client = DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
database = client.get_database("ASTRA_DB_API_ENDPOINT")

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

// Get a database
const client = new DataAPIClient('ASTRA_DB_APPLICATION_TOKEN');
const database = client.db('ASTRA_DB_API_ENDPOINT');

// Drop a table
(async function () {
  await database.dropTable("example_table", { ifExists: true });
})();
package com.example;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.commands.options.DropTableOptions;

public class DropTable {

    public static void main(String[] args) {
        // Get a database
        Database database = new DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
            .getDatabase("ASTRA_DB_API_ENDPOINT");

        // Drop a table
        DropTableOptions options = new DropTableOptions()
            .ifExists(true);
        database.dropTable("example_table", 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 | 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