Manage datasets
This document describes how to recreate datasets in another location, secure datasets, delete datasets, and restore tables from deleted datasets in BigQuery. For information about how to restore (or undelete) a deleted dataset, see Restore deleted datasets.
As a BigQuery administrator, you can organize and control access to tables and views that analysts use. For more information about datasets, see Introduction to datasets.
You cannot change the name of an existing dataset or relocate a dataset after it's created.
Required roles
This section describes the roles and permissions that you need to manage datasets. If your source or destination dataset is in the same project as the one you are using to copy, then you don't need extra permissions or roles on that dataset.
Delete a dataset
Grant these roles to delete a dataset.
To get the permissions that
you need to delete datasets,
ask your administrator to grant you the
BigQuery Data Owner (roles/bigquery.dataOwner) IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to delete datasets. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to delete datasets:
-
bigquery.datasets.deleteon the project -
bigquery.tables.deleteon the project
You might also be able to get these permissions with custom roles or other predefined roles.
Recreate datasets in another location
To manually move a dataset from one location to another, follow these steps:
-
Export the data from your BigQuery tables to a Cloud Storage bucket.
There are no charges for exporting data from BigQuery, but you do incur charges for storing the exported data in Cloud Storage. BigQuery exports are subject to the limits on extract jobs.
-
Copy or move the data from your export Cloud Storage bucket to a new bucket you created in the destination location. For example, if you are moving your data from the
USmulti-region to theasia-northeast1Tokyo region, you would transfer the data to a bucket that you created in Tokyo. For information about transferring Cloud Storage objects, see Copy, rename, and move objects in the Cloud Storage documentation.Transferring data between regions incurs network egress charges in Cloud Storage.
-
Create a new BigQuery dataset in the new location, and then load your data from the Cloud Storage bucket into the new dataset.
You are not charged for loading the data into BigQuery, but you will incur charges for storing the data in Cloud Storage until you delete the data or the bucket. You are also charged for storing the data in BigQuery after it is loaded. Loading data into BigQuery is subject to the load jobs limits.
You can also use Managed Service for Apache Airflow to move and copy large datasets programmatically.
For more information about using Cloud Storage to store and move large datasets, see Use Cloud Storage with big data.
Secure datasets
To control access to datasets in BigQuery, see Controlling access to datasets. For information about data encryption, see Encryption at rest.
Delete datasets
When you delete a dataset by using the Cloud de Confiance console, tables and views in the dataset, including their data, are deleted automatically. However, when using any other method, you must either empty the dataset first or specify corresponding flags, parameters or keywords that force removal of the dataset contents.
If you attempt to delete a non-empty dataset without the proper
flags or parameters, the operation fails with the following error:
Dataset project:dataset is still in use.
Deleting a dataset creates one audit log entry for the dataset deletion. It doesn't create separate log entries for each deleted table within the dataset.
To delete a dataset, select one of the following options:
Console
Go to the BigQuery page.
In the left pane, click Explorer:

In the Explorer pane, expand your project, click Datasets, and then click the dataset.
In the details pane, click Delete.
In the Delete dataset dialog, type
deleteinto the field, and then click Delete.
SQL
To delete a dataset, use the
DROP SCHEMA DDL statement.
The following example deletes a dataset named mydataset:
In the Cloud de Confiance console, go to the BigQuery page.
In the query editor, enter the following statement:
DROP SCHEMA IF EXISTS mydataset;
By default, this only works to delete an empty dataset. To delete a dataset and all of its contents, use the
CASCADEkeyword:DROP SCHEMA IF EXISTS mydataset CASCADE;
Click Run.
For more information about how to run queries, see Run an interactive query.
bq
Use the bq rm command
with the --dataset or -d flag, which is optional.
If your dataset contains tables, you must use the -r flag to
remove all tables in the dataset. If you use the -r flag, then you can omit
the --dataset or -d flag.
After you run the command, the system asks for confirmation. You can use the
-f flag to skip the confirmation.
If you are deleting a table in a project other than your default project,
add the project ID to the dataset name in the following format:
PROJECT_ID:DATASET.
bq rm -r -f -d PROJECT_ID:DATASET
Replace the following:
PROJECT_ID: your project IDDATASET: the name of the dataset that you're deleting
Examples:
Enter the following command to remove a dataset that's named mydataset and all
the tables in it from your default project. The command uses the
-d flag.
bq rm -r -d mydataset
When prompted, type y and press enter.
Enter the following command to remove mydataset and all the tables in it
from myotherproject. The command does not use the optional -d flag.
The -f flag is used to skip confirmation.
bq rm -r -f myotherproject:mydataset
You can use the bq ls command to confirm that the dataset was deleted.
API
Call the
datasets.delete method
to delete the dataset and set the deleteContents parameter to true to
delete the tables in it.
C#
The following code sample deletes an empty dataset.
Before trying this sample, follow the C# setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery C# API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
pip install google-cloud-bigquery-datatransfer. Then create a transfer configuration to copy the dataset.
The following code sample deletes a dataset and all of its contents:
Go
Before trying this sample, follow the Go setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Go API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
pip install google-cloud-bigquery-datatransfer. Then create a transfer configuration to copy the dataset.
Java
The following code sample deletes an empty dataset.
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
pip install google-cloud-bigquery-datatransfer. Then create a transfer configuration to copy the dataset.
The following code sample deletes a dataset and all of its contents:
Node.js
Before trying this sample, follow the Node.js setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Node.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
pip install google-cloud-bigquery-datatransfer. Then create a transfer configuration to copy the dataset.
PHP
Before trying this sample, follow the PHP setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery PHP API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
pip install google-cloud-bigquery-datatransfer. Then create a transfer configuration to copy the dataset.
Python
Before trying this sample, follow the Python setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Python API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
pip install google-cloud-bigquery-datatransfer. Then create a transfer configuration to copy the dataset.
Ruby
The following code sample deletes an empty dataset.
Before trying this sample, follow the Ruby setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Ruby API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
pip install google-cloud-bigquery-datatransfer. Then create a transfer configuration to copy the dataset.
The following code sample deletes a dataset and all of its contents:
Restore tables from deleted datasets
You can restore tables from a deleted dataset that are within the dataset's time travel window. To restore the entire dataset, see Restore deleted datasets.
- Create a dataset with the same name and in the same location as the original.
- Choose a timestamp from before the original dataset was deleted by using a
format of milliseconds since the epoch–for example,
1418864998000. Copy the
originaldataset.table1table at the time1418864998000into the new dataset:bq cp originaldataset.table1@1418864998000 mydataset.mytable
To find the names of the nonempty tables that were in the deleted dataset, query the dataset's
INFORMATION_SCHEMA.TABLE_STORAGEview within the time travel window.
Restore deleted datasets
To learn how to restore (or undelete) a deleted dataset, see Restore deleted datasets.
Quotas
For information about copy quotas, see Copy jobs.
Usage for copy jobs are available in the INFORMATION_SCHEMA. To learn how to
query the INFORMATION_SCHEMA.JOBS view, see
JOBS view.
Pricing
For pricing information for copying datasets, see Data replication pricing.
BigQuery sends compressed data for copying across regions so the data that is billed might be less than the actual size of your dataset. For more information, see BigQuery pricing.
What's next
- Learn how to create datasets.
- Learn how to update datasets.