Delete models

This page shows you how to delete BigQuery ML models. You can delete amodel by:

  • Using the Google Cloud console
  • Using the bq command-line tool'sbq rm command orbq query command
  • Calling themodels.deleteAPI method or calling thejobs.query method
  • Using the client libraries

You can only delete one model at a time. When you delete a model, anydata in the model is also deleted.

To automatically delete models after a specified period of time, set the model'sexpiration time when you create it using the bq command-line tool, the API, or the clientlibraries. If you did not set the expiration when the model was created, you canupdate the model's expiration time.

Limitations on deleting models

Deleting a model is subject to the following limitations:

  • You can't delete multiple models at the same time. You must delete themindividually.
  • You can't restore a deleted model.

Required permissions

To delete models in a dataset, you must be assigned theWRITERrole on the dataset, or you must be assigned a project-level Identity and Access Management (IAM) role thatincludesbigquery.models.delete permissions. If you are grantedbigquery.models.delete permissions at the project level, you can delete modelsin any dataset in the project. The following project-level IAM rolesincludebigquery.models.delete permissions:

  • bigquery.dataEditor
  • bigquery.dataOwner
  • bigquery.admin

For more information about IAM roles and permissions in BigQuery ML,seeAccess control.

Delete a model

To delete a model, do the following:

Console

You can delete a model in the Google Cloud console by using theDelete Model optionor by running a query that contains aDROP MODEL | DROP MODEL IF EXISTSDDL statement.

Option one: Use theDelete Model option.

  1. In the left pane, clickExplorer:

    Highlighted button for the Explorer pane.

    If you don't see the left pane, clickExpand left pane to open the pane.

  2. In theExplorer pane, expand your project, clickDatasets,and then click your dataset.

  3. Click theModels tab, and then click a model nameto select the model.

  4. Click the options icon forthe model and then clickDelete.

  5. In theDelete model dialog, typedelete and then clickDelete.

Option two: Use a DDL statement.

  1. In the Google Cloud console, go to the BigQuery page.

    Go to the BigQuery page

  2. ClickCompose new query.

  3. Type your DDL statement in theQuery editor text area.

    DROPMODELmydataset.mymodel

  4. ClickRun. When the query completes, the model is removed fromthe navigation pane.

bq

You can delete a model using the bq command-line tool by entering the:

  • bq rm command with the--model or-m flag
  • bq query command with the DDL statement as the query parameter

If you are deleting a model in a project other than your default project,add the project ID to the dataset in the following format:[PROJECT_ID]:[DATASET].[MODEL].

Option one: Enter thebq rm command

When you use thebq rm command to remove a model, you must confirm theaction. You can use the--force flag (or-f shortcut) to skip confirmation.

bq rm -f --modelPROJECT_ID:DATASET.MODEL

Replace the following:

  • PROJECT_ID is your project ID.
  • DATASET is the name of the dataset.
  • MODEL is the name of the model.

Therm command produces no output.

Examples:

Enter the following command to deletemymodel frommydataset.mydatasetis in your default project.

bq rm --model mydataset.mymodel

Enter the following command to deletemymodel frommydataset.mydatasetis inmyotherproject, not your default project.

bq rm --model myotherproject:mydataset.mymodel

Enter the following command to deletemymodel frommydataset.mydatasetis in your default project. The command uses the-f shortcut to bypassconfirmation.

bq rm -f --model mydataset.mymodel

You can confirm that the model was deleted by issuing thebq ls command.For more information, seeList models.

Option two: Enter thebq query command

To delete a model by using thebq query command, supply theDROP MODELstatement in the query parameter and supply the--use_legacy_sql=falseflag to specify GoogleSQL query syntax.

Examples:

Enter the following command to deletemymodel frommydataset.mydatasetis in your default project.

bq query --use_legacy_sql=false 'DROP MODEL mydataset.mymodel'

Enter the following command to deletemymodel frommydataset.mydatasetis inmyotherproject, not your default project.

bq query --use_legacy_sql=false \'DROP MODEL myotherproject:mydataset.mymodel'

API

Option one: Call themodels.delete method

To delete a model, call themodels.deletemethod and provide theprojectId,datasetId, andmodelId.

Option two: Call thejobs.query method

To delete a model, call thejobs.querymethod and supply theDROP MODEL DDL statement in the request body'squery property.

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")// deleteModel demonstrates deletion of BigQuery ML model.funcdeleteModel(projectID,datasetID,modelIDstring)error{// projectID := "my-project-id"// datasetID := "mydataset"// modelID := "mymodel"ctx:=context.Background()client,err:=bigquery.NewClient(ctx,projectID)iferr!=nil{returnfmt.Errorf("bigquery.NewClient: %w",err)}deferclient.Close()model:=client.Dataset(datasetID).Model(modelID)iferr:=model.Delete(ctx);err!=nil{returnfmt.Errorf("couldn't delete model: %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.BigQueryException;importcom.google.cloud.bigquery.BigQueryOptions;importcom.google.cloud.bigquery.ModelId;// Sample to delete a modelpublicclassDeleteModel{publicstaticvoidmain(String[]args){// TODO(developer): Replace these variables before running the sample.StringdatasetName="MY_DATASET_NAME";StringmodelName="MY_MODEL_NAME";deleteModel(datasetName,modelName);}publicstaticvoiddeleteModel(StringdatasetName,StringmodelName){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();booleansuccess=bigquery.delete(ModelId.of(datasetName,modelName));if(success){System.out.println("Model deleted successfully");}else{System.out.println("Model was not found");}}catch(BigQueryExceptione){System.out.println("Model 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();asyncfunctiondeleteModel(){// Deletes a model named "my_model" from "my_dataset"./**   * TODO(developer): Uncomment the following lines before running the sample   */// const datasetId = "my_dataset";// const modelId = "my_model";constdataset=bigquery.dataset(datasetId);constmodel=dataset.model(modelId);awaitmodel.delete();console.log(`Model${modelId} deleted.`);}

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.# model_id = 'your-project.your_dataset.your_model'client.delete_model(model_id)# Make an API request.print("Deleted model '{}'.".format(model_id))

Restore a deleted model

You can't restore a deleted model.

What's next

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.

Last updated 2026-02-18 UTC.