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 |
---|---|---|
|
|
The name of the table to drop, or a |
|
|
Optional if you specified a keyspace when instantiating the Default: The working keyspace for the database. |
|
|
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. See Drop a table only if the table exists for an example. Default: false |
|
|
Optional.
A timeout, in milliseconds, for the underlying HTTP request.
If not provided, the |
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 |
---|---|---|
|
|
The name of the table to drop. |
|
|
The options for this operation. See Properties of |
Name | Type | Summary |
---|---|---|
|
|
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. See Drop a table only if the table exists for an example. Default: false |
|
|
Optional if you specified a keyspace when instantiating the Default: The working keyspace for the database. |
|
|
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 |
---|---|---|
|
|
The name of the table to drop. |
|
Optional.
The options for this operation. See Methods of |
Method | Parameters | Summary |
---|---|---|
|
|
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. See Drop a table only if the table exists for an example. Default: false |
|
|
Optional if you specified a keyspace when instantiating the Default: The working keyspace for the database. |
|
|
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 |
---|---|---|
|
|
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.