How to format SQL
- Paste your query into the SQL input box, or press Upload .sql to open a file.
- Choose the Dialect it's written for (MySQL, PostgreSQL, T-SQL, SQLite, BigQuery, Snowflake, Oracle PL/SQL and more), and it is formatted as you type.
- Set Keyword case (upper, lower or preserve), Indent (2 spaces, 4 spaces or a tab) and Lines between queries to taste.
- Press Minify to collapse the result onto a single line instead.
- Press Copy or Download .sql to take the result with you. Ctrl+Enter (Cmd+Enter on a Mac) re-runs the last action.
SQL pretty print example
A one-line query is hard to review in a pull request or a log:
select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=1 group by u.id, u.name order by orders desc limit 10;Formatted with upper-case keywords and 2-space indentation, each clause gets its own line and the joined table and grouped columns are easy to scan:
SELECT
u.id,
u.name,
count(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.active = 1
GROUP BY
u.id,
u.name
ORDER BY
orders DESC
LIMIT
10;SQL minify: back to a single line
Minify does the reverse — useful for a log line, a URL parameter, or anywhere a multi-line string is awkward. The formatted example above collapses to:
select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.id, u.name order by orders desc limit 10;Minify formats first (so the query is tokenized correctly for the dialect you picked) and only then joins lines with a single space, so the result still means exactly the same query.
Dialect quirks: backticks, brackets, $1 and :named parameters
SQL dialects don't agree on how identifiers and parameters are written, so picking the right dialect matters. A few examples, all reformatted without disturbing the dialect-specific syntax:
MySQL / MariaDB use backtick-quoted identifiers:
select `id`, `name` from `users` where `id` = 1SELECT
`id`,
`name`
FROM
`users`
WHERE
`id` = 1T-SQL (SQL Server) uses [bracket]-quoted identifiers, and TOP instead of LIMIT:
select top 10 [Id], [Name] from [dbo].[Users] where [Active] = 1SELECT
TOP 10 [Id],
[Name]
FROM
[dbo].[Users]
WHERE
[Active] = 1PostgreSQL often uses $1, $2 positional parameters from application code:
select * from users where id = $1 and email = $2SELECT
*
FROM
users
WHERE
id = $1
AND email = $2SQLite (and many ORMs) support :name named parameters:
select * from users where id = :idSELECT
*
FROM
users
WHERE
id = :idComments and multiple statements are kept
Both -- line comments and /* block comments */ survive formatting exactly as written, wherever they appear:
select id,
name -- customer name
from customers /* active only */
where active = 1;SELECT
id,
name -- customer name
FROM
customers /* active only */
WHERE
active = 1;A file with several semicolon-separated statements is formatted statement by statement; Lines between queries controls how many blank lines separate them.
What is the best SQL formatter?
For everyday reformatting of a query someone pasted into a ticket or a Slack message, a dialect-aware browser tool that never uploads the text — like this one — is the fastest, lowest-risk option. If you format SQL constantly inside a specific database's IDE (DataGrip, DBeaver, Azure Data Studio, SSMS), that IDE's built-in formatter is worth learning too, since it runs on every file automatically and can understand your actual schema. Neither replaces reading the query.
SQL formatter vs beautifier vs minifier
- SQL formatter or beautifier: adds line breaks, indentation and consistent keyword case so a query is easy to read and review. This tool's Format button.
- SQL minifier: the reverse — collapses a query onto one line. This tool's Minify button.
- Neither one is a query optimizer or a linter: formatting never changes which rows a query returns or how fast it runs, and this tool doesn't flag anti-patterns like
SELECT *or a missing index.
Is my SQL query safe to paste here?
Formatting and minifying both run entirely in your browser's JavaScript; the query text never leaves your device, and there's no database connection for it to reach even if it wanted to. That matters more for SQL than for most text, because a real query can carry production table names, column names, or literal values a colleague pasted in while debugging. Only your settings — dialect, keyword case, indent size, lines between queries — are saved, in your browser's local storage, never the query itself.
More developer tools
- JSON formatter & validator: format, minify and validate the JSON your queries return.
- XML formatter & validator: the same pretty print and minify workflow for XML.
- HTML formatter & beautifier: pretty print and minify HTML templates.
- Diff checker: compare two versions of a query or migration side by side.
Frequently asked questions
What is the best free SQL formatter?
For a quick, private reformat that supports the exact dialect you're writing (MySQL, PostgreSQL, T-SQL, SQLite, BigQuery, Snowflake, Oracle PL/SQL and more), a browser tool like this one is fastest and never uploads the query. A full IDE like DataGrip, DBeaver or SSMS goes further for day-to-day work: it formats on save and understands your actual schema.
How can I beautify MySQL code?
Paste it into the box above, choose MySQL under Dialect, and it is formatted as you type — backtick-quoted identifiers like `users` and MySQL-specific syntax are handled correctly because the formatter is dialect-aware, not a generic text reindenter.
Does this tool run or validate my SQL against a database?
No, and it can't: there is no database connection here at all. It only reads the text of your query to work out where clauses, keywords and parentheses begin and end, the same way a syntax highlighter does, then rewrites the whitespace around them. Nothing is executed.
Will formatting or minifying change what my query does?
No. Only whitespace, line breaks and (if you choose upper or lower under Keyword case) the capitalization of keywords change. Table names, column names, string and number literals, operators and the order of clauses are all left exactly as you wrote them, so a formatted or minified query behaves identically to the original.
Why does the dialect I pick matter?
Because SQL dialects disagree on quoting and parameters: MySQL/MariaDB use backticks for identifiers (`col`), SQL Server/T-SQL use [brackets], PostgreSQL supports $1-style positional parameters, and SQLite/many ORMs use :named or ? placeholders. Picking the right dialect means the formatter tokenizes these correctly instead of misreading a backtick or a bracket as something else.
What does the parse error mean, and can Notepad++ format SQL too?
A parse error means the formatter couldn't make sense of the query's structure — usually an unbalanced parenthesis, a quote that's never closed, or (less often) syntax specific to a different dialect than the one you selected; try switching dialects if the query is valid in your database. Notepad++ itself has no built-in SQL formatter, but plugins like Poor Man's T-SQL Formatter add one for T-SQL specifically.
Are comments and multiple statements kept?
Yes. Both -- line comments and /* block comments */ are preserved exactly, and a file with several semicolon-separated statements is formatted statement by statement, with the number of blank lines between them controlled by "Lines between queries".
What does Minify do, and when would I use it?
Minify collapses a formatted query onto a single line, which is handy for pasting into a log message, a URL query string, a one-line config value, or anywhere a multi-line string is awkward. Because SQL's -- line comments run to the end of a line, minify first turns any into an equivalent /* block comment */ so nothing after it gets silently commented out once everything is joined.
Is my SQL query uploaded anywhere?
No — and this matters more here than on most formatters, because a real query can contain production table and column names, or even literal values. Formatting and minifying both run entirely in your browser; nothing you paste is sent to a server, logged or saved. Only your settings (dialect, keyword case, indent, lines between queries) are remembered on your device.
What SQL dialects are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, T-SQL (SQL Server), SQLite, BigQuery, Snowflake, Oracle PL/SQL, Amazon Redshift, Spark SQL, Trino/Presto, DuckDB, Apache Hive, ClickHouse, SingleStore, IBM Db2 (and Db2 for i), TiDB and Couchbase N1QL — everything the underlying sql-formatter library supports.