You can call the DeleteTable operation to delete a data table from an instance.
Usage notes
You cannot restore deleted data tables. Proceed with caution.
When you delete a data table, the data in the data table and the secondary indexes that are created for the data table are deleted. You cannot restore deleted data and secondary indexes. Proceed with caution.
Prerequisites
An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
A data table is created. For more information, see Create a data table.
If a search index is created for the data table that you want to delete, you must delete the search index before you delete the data table. For more information, see Delete search indexes.
API operation
DeleteTable(request *DeleteTableRequest) (*DeleteTableResponse, error)
Parameters
Parameter | Required | Description |
TableName | Yes | The name of the data table. You can call the ListTable operation to query the names of all tables in an instance. |
Examples
The following sample code provides an example on how to delete a data table:
func DeleteTableSample(client *tablestore.TableStoreClient, tableName string) {
deleteReq := new(tablestore.DeleteTableRequest)
deleteReq.TableName = tableName
_, err := client.DeleteTable(deleteReq)
if (err != nil) {
fmt.Println("Failed to delete table with error:", err)
} else {
fmt.Println("Delete table finished")
}
}
References
For more information about the API operation, see DeleteTable. For the complete sample code, visit DeleteTable@GitHub.
If an error occurs when you call the operation, find the error cause in Error codes based on the error message and handle the error.