SQL Formatter
SQL Formatter pretty print sql online private mysql postgresql sql formatter compact sql queryReveal a query's structure
Paste SQL, select the closest dialect and keyword style, then choose Format SQL. Compact output reduces layout whitespace when a query must fit into a log, configuration value, or test fixture.
Formatting helps review, not execution
Readable line breaks make joins, nested expressions, conditions, grouping, and ordering easier to inspect. Formatting should preserve query meaning, but it does not connect to a database or prove the statement is valid for a particular server version. Always run important changes through the database's parser, test environment, and normal review process.
Worked example
Paste select u.name,count(o.id) from users u left join orders o on o.user_id=u.id group by u.name order by count(o.id) desc. Formatting separates the SELECT list, FROM clause, JOIN condition, grouping, and ordering. Uppercase keywords help the grammatical structure stand apart from identifiers.
Choose a dialect and house style deliberately
Standard SQL is a useful default, but real engines differ in quoting, parameters, functions, operators, and procedural syntax. MySQL backticks, PostgreSQL casts, SQL Server brackets, BigQuery structures, and SQLite extensions need their matching dialect. Style controls cover indentation width and pattern, keyword and identifier case, function and data-type case, AND/OR placement, expression width, query spacing, tabs, operator spacing, and semicolon placement. Preferences are saved only in this browser. Reset settings restores the documented defaults.
Privacy, safety, and limitations
The query remains in this browser tab. No database connection is made. Formatting does not detect SQL injection, verify parameters, estimate performance, inspect indexes, authorize access, or confirm transaction safety. Compacting code can also make review harder; retain the readable source form when it is maintained by people.
SQL Formatter FAQ
Will formatted SQL run faster?
No. Whitespace layout normally does not change the database execution plan.
Does it validate table and column names?
No. The tool has no database schema or connection.
Which dialect should I choose?
Choose the engine that will execute the statement, especially when the query uses proprietary syntax.