Delete a table

Delete a table.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample

C#

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

// Clean up. Delete the table.
Console.WriteLine($"Delete table: {tableId}");

bigtableTableAdminClient.DeleteTable(name: tableName);
if (!TableExist(bigtableTableAdminClient))
{
    Console.WriteLine($"Table: {tableId} deleted successfully");
}

C++

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

google::cloud::Status status = table_admin.DeleteTable(table_id);
if (!status.ok()) throw std::runtime_error(status.message());

Go

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

log.Printf("Deleting the table")
if err = adminClient.DeleteTable(ctx, tableName); err != nil {
	log.Fatalf("Could not delete table %s: %v", tableName, err)
}

if err = adminClient.Close(); err != nil {
	log.Fatalf("Could not close admin client: %v", err)
}

Java

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

System.out.println("\nDeleting table: " + tableId);
try {
  adminClient.deleteTable(tableId);
  System.out.printf("Table %s deleted successfully%n", tableId);
} catch (NotFoundException e) {
  System.err.println("Failed to delete a non-existent table: " + e.getMessage());
}

Node.js

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

console.log('Delete the table');
await table.delete();

PHP

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

try {
    printf('Attempting to delete table %s.' . PHP_EOL, $tableId);
    $tableAdminClient->deleteTable($tableName);
    printf('Deleted %s table.' . PHP_EOL, $tableId);
} catch (ApiException $e) {
    if ($e->getStatus() === 'NOT_FOUND') {
        printf('Table %s does not exists' . PHP_EOL, $tableId);
    } else {
        throw $e;
    }
}

Python

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

print('Deleting the {} table.'.format(table_id))
table.delete()

Ruby

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

puts "Deleting the table #{table_id}"
table.delete

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.