[ Web Proxy ]
URL:
Viewing: https://cloud.google.com/bigquery/docs/data-manipulation-language [Back]  [Original]

Transform data with data manipulation language (DML)  |  BigQuery  |  Google Cloud Documentation Skip to main content
Google Cloud Documentation [Google Cloud Documentation]
Send feedback Stay organized with collections Save and categorize content based on your preferences.

Transform data with data manipulation language (DML)

The BigQuery data manipulation language (DML) lets you update, insert, and delete data from your BigQuery tables.

You can execute DML statements just as you would a SELECT statement, with the following conditions:

For more information about how to compute the number of bytes processed by a DML statement, see On-demand query size calculation.

Limitations

DML statements

The following sections describe the different types of DML statements and how you can use them.

INSERT statement

Use the INSERT statement to add new rows to an existing table. The following example inserts new rows into the table dataset.Inventory with explicitly specified values.

INSERT dataset.Inventory (product, quantity)
VALUES('whole milk', 10),
      ('almond milk', 20),
      ('coffee beans', 30),
      ('sugar', 0),
      ('matcha', 20),
      ('oat milk', 30),
      ('chai', 5)

/+-------------------+----------+
 |      product      | quantity |
 +-------------------+----------+
 | almond milk       |       20 |
 | chai              |        5 |
 | coffee beans      |       30 |
 | matcha            |       20 |
 | oat milk          |       30 |
 | sugar             |        0 |
 | whole milk        |       10 |
 +-------------------+----------+/

For more information about INSERT statements, see INSERT statement.

DELETE statement

Use the DELETE statement to delete rows in a table. The following example deletes all rows in the table dataset.Inventory that have the quantity value 0.

DELETE dataset.Inventory
WHERE quantity = 0

/+-------------------+----------+
 |      product      | quantity |
 +-------------------+----------+
 | almond milk       |       20 |
 | chai              |        5 |
 | coffee beans      |       30 |
 | matcha            |       20 |
 | oat milk          |       30 |
 | whole milk        |       10 |
 +-------------------+----------+/

To delete all rows in a table, use the TRUNCATE TABLE statement instead. For more information about DELETE statements, see DELETE statement.

TRUNCATE statement

Use the TRUNCATE statement to remove all rows from a table, but leave the table metadata intact, including table schema, description, and labels. The following example removes all rows from the table dataset.Inventory.

TRUNCATE dataset.Inventory

To delete specific rows in a table, use the DELETE statement instead. For more information about the TRUNCATE statement, see TRUNCATE statement.

UPDATE statement

Use the UPDATE statement to update existing rows in a table. The UPDATE statement must also include the WHERE keyword to specify a condition. The following example reduces the quantity value of rows by 10 for products that contain the string milk.

UPDATE dataset.Inventory
SET quantity = quantity - 10,
WHERE product LIKE '%milk%'

/+-------------------+----------+
 |      product      | quantity |
 +-------------------+----------+
 | almond milk       |       10 |
 | chai              |        5 |
 | coffee beans      |       30 |
 | matcha            |       20 |
 | oat milk          |       20 |
 | whole milk        |        0 |
 +-------------------+----------+/

UPDATE statements can also include FROM clauses to include joined tables. For more information about UPDATE statements, see UPDATE statement.

MERGE statement

The MERGE statement combines the INSERT, UPDATE, and DELETE operations into a single statement and performs the operations atomically to merge data from one table to another. For more information and examples about the MERGE statement, see MERGE statement.

Concurrent jobs

BigQuery manages the concurrency of DML statements that add, modify, or delete rows in a table.

Note: DML statements are subject to rate limits such as the maximum rate of table writes. You might hit a rate limit if you submit a high number of jobs against a table at one time. These rates do not limit the total number of DML statements that can be run. If you get an error message that says you've exceeded a rate limit, retry the operation using exponential backoff between retries.

INSERT DML concurrency

During any 24-hour period, the first 1500 INSERT statements run immediately after they are submitted. After this limit is reached, the concurrency of INSERT statements that write to a table is limited to 10. Additional INSERT statements are added to a PENDING queue. Up to 100 INSERT statements can be queued against a table at any given time. When an INSERT statement completes, the next INSERT statement is removed from the queue and run.

If you must run DML INSERT statements more frequently, consider streaming data to your table using the Storage Write API (gRPC).

UPDATE, DELETE, MERGE DML concurrency

The UPDATE, DELETE, and MERGE DML statements are called mutating DML statements. If you submit one or more mutating DML statements on a table while other mutating DML jobs on it are still running (or pending), BigQuery runs up to 2 of them concurrently, after which up to 20 are queued as PENDING. When a previously running job finishes, the next pending job is dequeued and run. Queued mutating DML statements share a per-table queue with maximum length 20. Additional statements past the maximum queue length for each table fail with the error message: Resources exceeded during query execution: Too many DML statements outstanding against table PROJECT_ID:DATASET.TABLE, limit is 20.

Interactive priority DML jobs that are queued for more than 7 hours fail with the following error message:

DML statement has been queued for too long

DML statement conflicts

Mutating DML statements that run concurrently on a table cause DML statement conflicts when the statements try to mutate the same partition. The statements succeed as long as they don't modify the same partition. BigQuery tries to rerun failed statements up to three times.

Fine-grained DML

Preview

This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the Service Specific Terms. You can process personal data for this feature as outlined in the Cloud Data Processing Addendum, subject to the obligations and restrictions described in the agreement under which you access Google Cloud. Pre-GA features are available "as is" and might have limited support. For more information, see the launch stage descriptions.

Note: To provide feedback or request support for this feature, send an email to bq-fine-grained-dml-feedback@google.com.

Fine-grained DML is a performance enhancement designed to optimize the execution of UPDATE, DELETE, and MERGE statements (also known as mutating DML statements).

Performance considerations

Without fine-grained DML enabled, DML mutations are performed at the file-group level, which can lead to inefficient data rewrites, especially for sparse mutations. This can lead to additional slot consumption and longer execution times.

Fine-grained DML is a performance enhancement designed to optimize these mutating DML statements by introducing a more granular approach that aims to reduce the amount of data that needs to be rewritten at the file-group level. This approach can significantly reduce the processing, I/O, and slot time consumed for mutating DML jobs.

There are some performance considerations to be aware of when using fine-grained DML:

Enable fine-grained DML

To enable fine-grained DML, set the enable_fine_grained_mutations table option to TRUE when you run a CREATE TABLE or ALTER TABLE DDL statement.

To create a new table with fine-grained DML, use the CREATE TABLE statement:

CREATE TABLE mydataset.mytable (
  product STRING,
  inventory INT64)
OPTIONS(enable_fine_grained_mutations = TRUE);

To alter an existing table with fine-grained DML, use the ALTER TABLE statement:

ALTER TABLE mydataset.mytable
SET OPTIONS(enable_fine_grained_mutations = TRUE);

To alter all existing tables in a dataset with fine-grained DML, use the ALTER TABLE statement:

FOR record IN
 (SELECT CONCAT(table_schema, '.', table_name) AS table_path
 FROM mydataset.INFORMATION_SCHEMA.TABLES)
DO
 EXECUTE IMMEDIATE
   "ALTER TABLE " || record.table_path || " SET OPTIONS(enable_fine_grained_mutations = TRUE)";
END FOR;

After the enable_fine_grained_mutations option is set to TRUE, mutating DML statements are run with fine-grained DML capabilities enabled and use existing DML statement syntax.

To determine if a table has been enabled with fine-grained DML, query the INFORMATION_SCHEMA.TABLES view. The following example checks which tables within a dataset have been enabled with this feature:

SELECT
  table_schema AS datasetId,
  table_name AS tableId,
  is_fine_grained_mutations_enabled
FROM
  DATASET_NAME.INFORMATION_SCHEMA.TABLES;

Replace DATASET_NAME with the name of the dataset in which to check if any tables have fine-grained DML enabled.

Disable fine-grained DML

To disable fine-grained DML from an existing table, use the ALTER TABLE statement.

ALTER TABLE mydataset.mytable
SET OPTIONS(enable_fine_grained_mutations = FALSE);

When disabling fine-grained DML, it may take some time for all deleted data to be fully processed, see Deleted data considerations. As a result, fine-grained DML limitations may persist until this has occurred.

Pricing

Enabling fine-grained DML for a table can incur additional costs. These costs include the following:

You can use BigQuery reservations to allocate dedicated BigQuery compute resources to process offloaded deleted data jobs. Reservations let you set a cap on the cost of performing these operations. This approach is particularly useful, and often recommended, for very large tables with frequent fine-grained mutating DML operations, which otherwise would have high on-demand costs due to the large number of bytes processed when performing each offloaded deleted data processing job.

Fine-grained DML's offloaded deleted data processing jobs are considered background jobs and require the use of the BACKGROUND reservation assignment type, rather than the QUERY reservation assignment type. Projects that perform fine-grained DML operations without a BACKGROUND assignment use on-demand pricing to process the offloaded deleted data jobs.

Operation On-demand pricing Capacity-based pricing
Mutating DML statements Use standard DML sizing to determine on-demand bytes scanned calculations.

Enabling fine-grained DML won't reduce the amount of scanned bytes of the DML statement itself.

Consume slots assigned with a QUERY type at statement run time.
Offloaded deleted data processing jobs Use standard DML sizing to determine on-demand bytes scanned calculations when deleted data processing jobs are run. Consume slots assigned with a BACKGROUND type when deleted data processing jobs are run.

Deleted data considerations

Fine-grained DML operations use a hybrid approach to manage deleted data, combining inline processing with offloaded garbage collection to distribute rewrite costs and optimize performance across multiple mutating DML statements issued against a table.

During the execution of a mutating DML statement, BigQuery attempts to perform a portion of relevant garbage collection from prior DML statements inline. Any deleted data not handled inline is offloaded to a background process for later cleanup.

Projects that perform fine-grained DML operations with a BACKGROUND assignment process offloaded garbage collection tasks using slots. Processing deleted data is subject to the configured reservation's resource availability. If there aren't enough resources available within the configured reservation, processing offloaded garbage collection operations might take longer than anticipated.

Projects that perform fine-grained DML operations by using on-demand pricing, or without a BACKGROUND assignment, process offloaded garbage collection tasks using internal BigQuery resources and are charged at on-demand pricing rates. For more information, see Pricing.

The timing of offloaded garbage collection tasks is determined by the frequency of DML activity on the table and the availability of resources, if using a BACKGROUND assignment:

To identify offloaded fine-grained DML deleted data processing jobs, query the INFORMATION_SCHEMA.JOBS view:

SELECT
  *
FROM
  region-us.INFORMATION_SCHEMA.JOBS
WHERE
  job_id LIKE "%fine_grained_mutation_garbage_collection%"

Limitations

Tables enabled with fine-grained DML are subject to the following limitations:

Best practices

For best performance, Google recommends the following patterns:

For best practices to optimize query performance, see Introduction to optimizing query performance.

What's next

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-08-18 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-18 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page