---
title: "Execute batch SQL statements in a transaction"
method: POST
path: "/api/db/{project_id}/batch"
tags: ["Database"]
---

# Execute batch SQL statements in a transaction

`POST /api/db/{project_id}/batch`

## Request

- Base URL: `https://core.blink.new`
- URL: `https://core.blink.new/api/db/{project_id}/batch`
- Auth: HTTP bearer

Execute multiple SQL statements atomically in a single transaction: all succeed or all roll back, no partial writes on a mid-batch failure. Each statement accepts its own positional parameters via `args`. `mode` selects the transaction variant — `"write"` (default), `"read"` for read-only batches, or `"deferred"`.

## Path parameters

- `project_id` string, required

## Request body

- BatchRequest
  - `statements` object[], required: Array of SQL statements to execute in transaction
    - `sql` string, required: SQL statement to execute
    - `args` union[]: Parameters for this statement
      - union
        - string
        - number
        - boolean
  - `mode` 'read' | 'write' | 'deferred': Transaction mode: write for data modifications, read for read-only queries, deferred to start as read and upgrade to write on the first mutation

## Response `200`

Batch executed successfully

- BatchResponse
  - `results` object[]: Results from each statement in the batch
    - `rows` object[]
    - `columns` string[]
    - `rowCount` integer
  - `executionTime` number: Total execution time in milliseconds
  - `success` boolean: Whether the batch operation succeeded

## Other responses

- `400`: Missing/invalid statements array, an invalid mode, or a manual transaction statement
- `401`: Authentication required or invalid API key
- `403`: Service role required
- `404`: No database found for the given project_id
- `500`: Internal server error

---

[API](https://skmtc.dev/blink/apis/blink-apis.md) - [All operations](https://skmtc.dev/blink/apis/blink-apis/llms.txt) - [OpenAPI document](https://skmtc.dev/blink/apis/blink-apis/revisions/4c59c706078e?raw)
