Skip to content

SQL FormatterBeta

Reformat SQL onto readable lines by clause (SELECT, FROM, WHERE …). Pick a dialect — MySQL, PostgreSQL, T-SQL and more. Nothing you paste leaves your browser.

0 characters · 0 lines
Keyword case

Output0 characters · 0 lines

How to use it

Paste your SQL into the input box and it’s broken onto separate, indented lines by clause (SELECT, FROM, WHERE, JOIN, and so on) so it’s easy to read. Pick the database you’re using under Language, and adjust keyword case (upper, lower, or as typed), indent width (2 spaces, 4 spaces, or a tab), and the number of blank lines between queries to your taste. Paste several queries separated by semicolons (;) and each one gets formatted.

Dialects have different syntax

SQL has a standard, but real databases each bend the syntax a little differently. BigQuery, for instance, wraps table names in backticks (`), while T-SQL (SQL Server) has its own TOP N clause and square-bracketed identifiers. Picking the wrong dialect can make an otherwise valid query fail to parse, so it’s worth choosing, under Language, the dialect that matches the DBMS you actually use: Standard SQL, MySQL, PostgreSQL, SQLite, T-SQL (SQL Server), or BigQuery.

When something goes wrong

If the SQL you pasted can’t be parsed by the formatting engine’s grammar, you’ll get an error message instead of a result. When the library can tell where it got stuck, the line and column are shown too — check around that spot for an unclosed parenthesis or syntax the chosen dialect doesn’t support.

Why there’s no “minify” option

This tool only pretty-prints; it doesn’t offer a way to collapse everything onto one line. Safely removing whitespace without touching what’s inside string literals or comments requires fully parsing the SQL, and the library it uses (sql-formatter) doesn’t have that feature — building a naive version ourselves would risk mangling string contents. If you want a more compact result, try a narrower indent width and set the blank lines between queries to zero instead.

Privacy

The SQL you paste is processed entirely in this browser tab and is never stored or transmitted anywhere. The formatting engine (sql-formatter) is only downloaded by your browser when needed and runs locally — it never sends your query anywhere.

Sources

Frequently asked questions

Which dialect should I pick?

Pick whichever matches the database you're using. If you're on a specific DBMS like MySQL, PostgreSQL, or SQLite, choose that one; if you're not tied to a specific engine or you're writing plain standard syntax, choose "Standard SQL". Dialects differ in details like how strings are quoted or how identifiers are written (BigQuery's backticks, T-SQL's square brackets), so picking the wrong one can make a perfectly valid query show up as an error.

Why isn't there a minify (single-line) option?

Safely collapsing whitespace — without touching whitespace inside string literals or comments — requires fully parsing the SQL, and the library this tool uses (sql-formatter) only pretty-prints; it doesn't offer a single-line mode. Rather than bolt on a naive whitespace stripper that risks corrupting string contents, this tool leaves it out. If you want something more compact, try a narrower indent width and zero blank lines between queries instead.

Can it format several queries separated by semicolons at once?

Yes. Paste multiple queries separated by semicolons (;) and each one gets formatted; the "Blank lines between queries" option controls how many blank lines go between them.

Does it handle complex or dialect-specific syntax?

Most of the time, yes. But formatting requires actually parsing the SQL, so syntax the chosen dialect doesn't support — or SQL with a genuine syntax error — shows up as an error instead of a formatted result, with the line and column where parsing got stuck when the library can tell.

Open-source software used: sql-formatter (MIT), nearley (MIT)