SQL Beautifier
Format SQL queries with dialect-aware rules.
SQL Beautifier – Free Online SQL Formatter
Queries generated by ORMs, copied from logs, or written in a hurry tend to be one long line. The SQL beautifier formats them so each clause starts on a new line, column lists are broken up, joins and conditions are indented, and keywords have consistent casing.
Supported SQL dialects
Pick the dialect that matches your database so its syntax is recognized:
- Standard SQL, MySQL, and MariaDB – backtick identifiers,
LIMIT,ON DUPLICATE KEY. - PostgreSQL –
::casts,RETURNING, dollar-quoted strings, JSON operators. - SQLite, SQL Server (T-SQL) with
[brackets]andTOP, Oracle PL/SQL. - BigQuery and Snowflake for analytics warehouses.
Options
- Keywords – UPPERCASE (most common), lowercase, or keep them as typed.
- Indentation – 2 spaces, 4 spaces, or tabs.
What the formatter does
Formatting is powered by the open-source sql-formatter library. SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY start new lines; each selected column gets its own line; JOIN … ON clauses are aligned; AND/OR conditions are placed on separate lines; and subqueries are indented one level deeper. Several statements separated by semicolons are formatted one after the other with blank lines between them. String literals, comments, and quoted identifiers are never changed.
Why format SQL?
Readable SQL is easier to debug and review. You can see at a glance which tables are joined, which filters apply, and whether a GROUP BY matches the selected columns. Consistently formatted queries also produce clean diffs in migration files.
Related SQL tools
Remove whitespace and comments with the SQL Minifier, inspect INSERT data as tables in the SQL Viewer, or convert results with SQL to JSON and SQL to CSV.
Frequently Asked Questions
Does the SQL formatter run my query?
No. It only rewrites whitespace and keyword case. Nothing is sent to a database, and the tool runs entirely in your browser.
Why do I get a parse error?
The formatter needs to tokenize the query. Unclosed quotes, unbalanced parentheses, or syntax from a different dialect (for example T-SQL brackets with the MySQL dialect selected) cause errors. Pick the right dialect and check the reported position.
Are comments kept?
Yes. Both -- line comments and /* block */ comments are preserved in place.
Which dialect should I choose if I'm not sure?
Standard SQL works for most simple queries. Choose your database's dialect when you use vendor-specific syntax such as PostgreSQL casts or T-SQL brackets.