Delete a dataset Stay organized with collections Save and categorize content based on your preferences.
Delete a dataset from a project.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
C#
Before trying this sample, follow theC# setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryC# API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
usingGoogle.Cloud.BigQuery.V2;usingSystem;publicclassBigQueryDeleteDataset{publicvoidDeleteDataset(stringprojectId="your-project-id",stringdatasetId="your_empty_dataset"){BigQueryClientclient=BigQueryClient.Create(projectId);// Delete a dataset that does not contain any tablesclient.DeleteDataset(datasetId:datasetId);Console.WriteLine($"Dataset {datasetId} deleted.");}}Go
Before trying this sample, follow theGo setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryGo API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
import("context""fmt""cloud.google.com/go/bigquery")// deleteDataset demonstrates the deletion of an empty dataset.funcdeleteDataset(projectID,datasetIDstring)error{// projectID := "my-project-id"// datasetID := "mydataset"ctx:=context.Background()client,err:=bigquery.NewClient(ctx,projectID)iferr!=nil{returnfmt.Errorf("bigquery.NewClient: %w",err)}deferclient.Close()// To recursively delete a dataset and contents, use DeleteWithContents.iferr:=client.Dataset(datasetID).Delete(ctx);err!=nil{returnfmt.Errorf("couldn't delete dataset: %w",err)}returnnil}Java
Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
importcom.google.cloud.bigquery.BigQuery;importcom.google.cloud.bigquery.BigQuery.DatasetDeleteOption;importcom.google.cloud.bigquery.BigQueryException;importcom.google.cloud.bigquery.BigQueryOptions;importcom.google.cloud.bigquery.DatasetId;publicclassDeleteDataset{publicstaticvoidmain(String[]args){// TODO(developer): Replace these variables before running the sample.StringprojectId="MY_PROJECT_ID";StringdatasetName="MY_DATASET_NAME";deleteDataset(projectId,datasetName);}publicstaticvoiddeleteDataset(StringprojectId,StringdatasetName){try{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.BigQuerybigquery=BigQueryOptions.getDefaultInstance().getService();DatasetIddatasetId=DatasetId.of(projectId,datasetName);booleansuccess=bigquery.delete(datasetId,DatasetDeleteOption.deleteContents());if(success){System.out.println("Dataset deleted successfully");}else{System.out.println("Dataset was not found");}}catch(BigQueryExceptione){System.out.println("Dataset was not deleted. \n"+e.toString());}}}Node.js
Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
// Import the Google Cloud client libraryconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();asyncfunctiondeleteDataset(){// Deletes a dataset named "my_dataset"./** * TODO(developer): Uncomment the following lines before running the sample. */// const datasetId = 'my_dataset';// Create a reference to the existing datasetconstdataset=bigquery.dataset(datasetId);// Delete the dataset and its contentsawaitdataset.delete({force:true});console.log(`Dataset${dataset.id} deleted.`);}PHP
Before trying this sample, follow thePHP setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPHP API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
use Google\Cloud\BigQuery\BigQueryClient;/** * Deletes the given dataset * * @param string $projectId The project Id of your Google Cloud Project. * @param string $datasetId The BigQuery dataset ID. */function delete_dataset(string $projectId, string $datasetId): void{ $bigQuery = new BigQueryClient([ 'projectId' => $projectId, ]); $dataset = $bigQuery->dataset($datasetId); $table = $dataset->delete(); printf('Deleted dataset %s' . PHP_EOL, $datasetId);}Python
Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
fromgoogle.cloudimportbigquery# Construct a BigQuery client object.client=bigquery.Client()# TODO(developer): Set model_id to the ID of the model to fetch.# dataset_id = 'your-project.your_dataset'# Use the delete_contents parameter to delete a dataset and its contents.# Use the not_found_ok parameter to not receive an error if the dataset has already been deleted.client.delete_dataset(dataset_id,delete_contents=True,not_found_ok=True)# Make an API request.print("Deleted dataset '{}'.".format(dataset_id))Ruby
Before trying this sample, follow theRuby setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryRuby API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
What's next
To search and filter code samples for other Google Cloud products, see theGoogle Cloud sample browser.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.