---
title: "Export a SQL script | Speedscale Docs"
description: "Download recorded PostgreSQL, MySQL, SQL Server and Oracle statements from the Speedscale dashboard as a .sql script that psql, mysql or sqlcmd can run: every executed statement in recorded order with its bound values filled in, from the Traffic page or one connection."
canonical: "https://docs.speedscale.com/guides/databases/export-sql-script/"
---

[Documentation index](https://docs.speedscale.com/guides/llms.txt) | [Markdown](https://docs.speedscale.com/guides/databases/export-sql-script/index.md) | [Canonical page](https://docs.speedscale.com/guides/databases/export-sql-script/)

# Export a SQL script

The Traffic page can download the statements your services ran as a plain `.sql` file: every executed statement in the order it ran, with the values of prepared statements filled in as literals. Run it with `psql`, `mysql` or `sqlcmd` to reproduce a production bug on a scratch database, hand it to a DBA, attach it to a ticket, or diff two of them.

It is the database counterpart of exporting a trace as a script in SQL Server Profiler, it works on SQL Server and Oracle traffic as well as Postgres and MySQL, and it reads the recorded traffic, so you need no access to the production database.

<a id="from-the-traffic-page"></a>

## From the Traffic page

Filter the grid to the statements you want, then choose **Export SQL** next to **Save** and **Replay**. The script holds the Postgres, MySQL, SQL Server and Oracle statements that match the current filters and time range, so filter first to narrow it to a service, a table, a session or an incident's few minutes. [Watch live SQL](https://docs.speedscale.com/guides/databases/watch-live-sql/) and [Find statements with filters](https://docs.speedscale.com/guides/databases/find-statements/) show how.

![The Traffic toolbar with Export SQL next to Replay, and its tooltip: download the Postgres, MySQL and SQL Server statements matching these filters and time range as a runnable .sql script, bound parameters inlined](https://docs.speedscale.com/assets/images/export-button-3122c493717d161746dab73af1c7e80b.png)

<a id="from-one-connection"></a>

## From one connection

Open a Postgres, MySQL, SQL Server or Oracle call and go to its **Connection** tab, then choose **Export as .sql**. The script holds that connection's statements in order, which is the easiest way to replay what one session did, transactions included. The button is hidden when the recording cannot tell that connection apart from others.

![The Connection tab of a Postgres call: 32 requests on this connection, a committed transaction chip, the Export as .sql button, and the connection's login, inserts, selects and updates in order](https://docs.speedscale.com/assets/images/connection-export-152b22b8e9d83589e82199a73ea27234.png)

<a id="what-the-script-holds"></a>

## What the script holds

*   One statement per execution, with its bound parameters filled in as literals, quoted and typed for the database.
*   For SQL Server, each recorded batch or RPC as its own batch ending in `GO`, as `sqlcmd` and SQL Server Management Studio expect.
*   A comment before each statement with its time, duration and outcome: the rows it returned or changed, or the error.
*   Logins, logouts and changes of connection as comments, so a script that covers several connections says which one ran what.
*   A statement whose values were not captured, or whose SQL was prepared before recording started, written commented out with the reason, never with unbound placeholders.

After the download, a message says how many statements were exported and how many are commented out. A filtered export holds at most the first 500 matching database requests and about 3 MB of SQL; when it stops short, the message says so, and a narrower filter or time range gets the rest.

[Export a SQL script in proxymock](https://docs.speedscale.com/proxymock/databases/export-sql-script/#what-the-script-holds) shows an example script.

Replaying writes changes data, so run a script against a database you can throw away.

<a id="related"></a>

## Related

*   [Inspect a statement](https://docs.speedscale.com/guides/databases/inspect-a-statement/)
*   [Load and Regression Test a Database](https://docs.speedscale.com/proxymock/databases/load-and-regression-testing/), to replay the statements with many sessions instead of once
