fjordtools / Data / SQL Formatter

SQL Formatter & Beautifier

Format and beautify SQL for PostgreSQL, MySQL, SQLite and more. Clauses and subqueries on their own lines, your choice of keyword case. Strings and comments stay untouched. Runs in your browser.

SQL
Formatted

      
About SQL Formatterhow it works and good to know

What it changes, and what it never does

The formatter only changes whitespace and, if you choose, the case of SQL keywords. Every token you typed is still there in the same order: string literals, quoted names, comments, numbers and operators are copied exactly. Each clause (FROM, WHERE, GROUP BY, joins) starts on its own line, select lists and VALUES get one item per line, and AND / OR conditions line up under the clause.

Any dialect

The layout works from keywords and brackets, not from a full grammar for one database, so it handles PostgreSQL, MySQL, SQLite, SQL Server and Oracle queries, including WITH queries, subqueries, window functions, CASE and several statements separated by semicolons. Unusual syntax is laid out as well as it can be and is never rejected or rewritten.

How it is tested

For thousands of generated queries, SQLite compiles the original and the formatted text to the identical program, so formatting cannot change what a query means. Formatting an already formatted query changes nothing.

Privacy

Your queries are formatted in your browser. They are not uploaded or stored, which matters when a query contains table names or values from a real system.

Related tools