- Tools
- SQL Formatter
Free tool
SQL Formatter
Paste a messy query and get clean, indented, readable SQL. Choose your database dialect and keyword style, then copy the result. Everything runs in your browser.
SELECT
u.id,
u.name,
count(o.id) AS order_count
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.created_at > '2024-01-01'
AND u.status IN ('active', 'trialing')
GROUP BY
u.id,
u.name
HAVING
count(o.id) > 3
ORDER BY
order_count DESC
LIMIT
20;A faster way to read your SQL
SQL that works and SQL that reads well are two different things. A query pasted from an application log or a chat message often arrives on a single line, with random spacing and mixed casing. It runs fine, but nobody can review it at a glance. This formatter fixes the layout so the structure of the query becomes obvious.
It puts each clause on its own line, indents the columns and conditions underneath, and lines up joins so you can trace how the tables connect. The result is the same query you started with, laid out the way you would write it by hand if you had the time.
How to format SQL
- 1Paste your query into the left pane, or load the example to see it work.
- 2Pick the database dialect that matches your query, such as PostgreSQL, MySQL, or SQL Server, so quoting and functions are handled correctly.
- 3Set keyword casing and indentation to match your team style. The formatted output updates as you type.
- 4Copy the clean query from the right pane and paste it back into your editor.
Why format SQL at all
Consistent formatting saves time in three places. Code review gets faster because a reviewer can see the shape of a query without mentally parsing it first. Bugs get easier to spot, since a missing join condition or a stray comma stands out once every clause sits on its own line. And version control diffs stay small, because a shared format means changes show up as real edits rather than whitespace noise.
Formatting also flattens the learning curve for anyone new to a codebase. A well laid out query reads top to bottom, from the columns you select down to the order you return them in, which is far kinder than a wall of text that scrolls off the right edge of the screen.
Every major dialect, nothing uploaded
Different databases speak slightly different SQL. The formatter understands standard SQL along with PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, BigQuery, Snowflake, Redshift, and Spark, so identifier quoting and dialect functions come out right for the database you actually use.
The formatting runs as JavaScript inside your browser tab. Your query is never sent to a server, which means you can paste SQL that references real table and column names without it leaving your machine.
Frequently asked questions
- What does a SQL formatter do?
- A SQL formatter takes a query written on one long line or with inconsistent spacing and rewrites it with consistent indentation, line breaks, and keyword casing. The logic of the query stays identical. Only the whitespace and layout change, which makes the query easier to read, review, and debug.
- Is this SQL formatter free?
- Yes. The formatter is free to use with no sign-up, and there is no cap on how many queries you can format.
- Is my SQL sent to a server?
- No. All formatting happens locally in your browser using JavaScript. Your query never leaves your machine, so you can safely format SQL that contains table names, column names, or values from a private database.
- Which SQL dialects are supported?
- The formatter handles standard SQL plus PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Snowflake, Redshift, and Spark SQL. Pick the dialect that matches your database so syntax such as quoting and functions is handled correctly.
- Can I choose uppercase or lowercase keywords?
- Yes. Use the Keywords control to force keywords like SELECT and WHERE to uppercase, force them to lowercase, or preserve the casing you typed. You can also switch between two-space, four-space, and tab indentation.
- Does formatting change what my query returns?
- No. Formatting only adjusts whitespace, line breaks, and keyword casing. The tables, columns, filters, and joins are untouched, so a formatted query returns exactly the same result as the original.
More free tools
Run your queries in DB Pro
A formatter cleans up a query after you write it. DB Pro helps you write it in the first place. It is a desktop database client for macOS, Windows, and Linux with a SQL editor that formats and autocompletes as you type, plus a data browser and schema explorer for PostgreSQL, MySQL, SQLite, and more.
Prefer to keep exploring first? Browse the free tools or read the database tutorials and cheat sheets.