// free tool

SQL formatter

Paste messy SQL, get clean, consistent SQL back. This is the same formatter that ships in the SQLly desktop app, compiled to WebAssembly - it runs entirely in your browser, so your SQL never leaves your device.

Drop a .sql file here to open it. It is read in your browser, not uploaded.

Formatted SQL
SELECT TOP 5
    o.[OrderID],
    c.CompanyName,
    SUM(od.UnitPrice * od.Quantity) AS Total
FROM
    dbo.Orders o
    INNER JOIN dbo.Customers c ON c.CustomerID = o.CustomerID
    INNER JOIN [Order Details] od ON od.OrderID = o.OrderID
WHERE
    o.OrderDate >= '2024-01-01'
GROUP BY
    o.OrderID,
    c.CompanyName
ORDER BY
    Total DESC

Loading the formatter…

Shortcuts in the editor: Ctrl+Enter formats and Ctrl+Shift+Enter minifies (⌘ instead of Ctrl on a Mac). Your settings are remembered in this browser and kept in the page address, so a link shares your style – never your SQL.

What this SQL formatter does

It reads your SQL the way a database would - as tokens, not as text - and lays it out consistently: one clause per line, indented select lists, aligned joins, and the keyword casing you prefer. Comments stay where you put them and string literals are never touched.

  • Dialect-aware. T-SQL [brackets], #temp tables and GO batches, PostgreSQL $$ bodies, :: casts and JSONB operators, MySQL `backticks` and @variables - each dialect is read with its own rules.
  • Safe by design. The output is re-checked token by token against your input. If anything but whitespace and casing would change, you get your SQL back untouched - and the page tells you why, down to the line and column.
  • Every setting from the app. Open Advanced settings for the full set of layout options the desktop app has: JOIN and ON placement, CASE and IN-list layout, CTE and subquery style, DDL alignment, per-category keyword casing and more.
  • Shows what changed. The result is syntax-highlighted with line numbers, the status line counts what changed besides whitespace, and Changes shows a line-by-line comparison with your input.
  • Private. Formatting happens in your tab. Nothing is uploaded, logged or stored; opened files are read by your browser.
  • Minify too. Need one line for a log, a JSON payload or a command line? Minify collapses the query while keeping literals, optimizer hints and anything written touching exactly as it was.

SQL formatter for your dialect

Each dialect page opens the same tool with its dialect preselected, and explains how its syntax is handled.

Examples

T-SQL formatter: a SQL Server report query

Before
select top 5 o.[OrderID],c.CompanyName,sum(od.UnitPrice*od.Quantity) as Total from dbo.Orders o inner join dbo.Customers c on c.CustomerID=o.CustomerID inner join [Order Details] od on od.OrderID=o.OrderID where o.OrderDate>='2024-01-01' group by o.OrderID,c.CompanyName order by Total desc
After
SELECT TOP 5
    o.[OrderID],
    c.CompanyName,
    SUM(od.UnitPrice * od.Quantity) AS Total
FROM
    dbo.Orders o
    INNER JOIN dbo.Customers c ON c.CustomerID = o.CustomerID
    INNER JOIN [Order Details] od ON od.OrderID = o.OrderID
WHERE
    o.OrderDate >= '2024-01-01'
GROUP BY
    o.OrderID,
    c.CompanyName
ORDER BY
    Total DESC

PostgreSQL formatter: a CTE

Before
with recent as (select customer_id, count(*) as n from orders where created_at > now() - interval '30 days' group by customer_id) select c.email, r.n from customers c join recent r using (customer_id) where r.n >= 3 order by r.n desc limit 20;
After
WITH
    recent AS (
        SELECT
            customer_id,
            COUNT(*) AS n
        FROM
            orders
        WHERE
            created_at > NOW() - INTERVAL '30 days'
        GROUP BY
            customer_id
    )
SELECT
    c.email,
    r.n
FROM
    customers c
    JOIN recent r USING (customer_id)
WHERE
    r.n >= 3
ORDER BY
    r.n DESC
LIMIT 20;

Both outputs use the Standard style with 4-space indents, exactly as the formatter above produces it. Switch the style to Compact for denser SQL or Expanded for leading commas and one item per line. The formatter docs cover the details.

SQL formatter FAQ

Is this SQL formatter free?

Yes. It is free to use with no sign-up and no usage limits. It is the formatter from the SQLly desktop app, published as a free web tool.

Is my SQL sent to a server?

No. The formatter is compiled to WebAssembly and runs inside your browser tab. Your SQL is never uploaded, logged or stored, and once the page has loaded it keeps working offline.

Which SQL dialects does it support?

T-SQL for SQL Server and Azure SQL, PostgreSQL, MySQL and MariaDB, SQLite and Oracle. Snowflake and Redshift are formatted with the PostgreSQL rules and BigQuery with the MySQL rules. Auto-detect picks T-SQL when it sees [bracketed] names, @parameters or a GO line, MySQL when it sees `backticks`, and PostgreSQL otherwise.

Can formatting break my query?

It is built not to. After formatting, SQLly checks its output token by token against your input. If anything other than whitespace and the casing you asked for would change, it gives your SQL back exactly as you wrote it and tells you why. SQL that does not parse cleanly, such as an unterminated string, is also left untouched, with the line and column of the problem.

How do I keep part of a query exactly as written?

Wrap it in -- formatter:off and -- formatter:on comments. Everything between them passes through untouched, which is handy for hand-aligned lists or generated code.

Can I share my formatting settings with my team?

Yes. Every setting, including the advanced ones, is kept in the page address after the # sign, so copying the address or pressing Copy settings link shares your exact style. The link holds the settings only, never your SQL.

Can I format SQL automatically while I work?

Yes, in the SQLly desktop app for macOS, Windows and Linux. Run Format SQL from the Query menu or the command palette, or turn on Format on save and Format on paste, with the same settings as the Advanced panel here.

// formatting is the least of it

Like the formatter? Meet the rest of SQLly

A native SQL workbench for macOS, Windows and Linux with IntelliSense that knows your schema, guardrails for risky queries, and this formatter built into the editor.