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 |
---|---|---|
|
|
Either the name of a table or a |
|
|
If If |
|
|
A timeout, in milliseconds, for the underlying schema-changing HTTP request.
If not provided, the |
Name | Type | Summary |
---|---|---|
|
|
The name of the table to drop, if dropping through a |
|
|
The options for this operation |
Options (DropTableOptions
):
Name | Type | Summary |
---|---|---|
|
|
If If |
|
|
If dropping through a |
|
|
The client-side timeout for this operation. |
Name | Type | Summary |
---|---|---|
|
|
The name of the table to drop, if dropping through a |
|
Specialization of the operation:
|
Name | Type | Summary |
---|---|---|
|
|
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. |
|
|
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.