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.
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
- JSON FormatterFormat, validate, minify and sort JSON.
- Text DiffCompare two texts or JSON documents line by line.
- Regex TesterTest JavaScript regular expressions with live match highlighting.
- Base64Encode and decode text, with URL-safe and UTF-8 support.
- URL EncoderPercent-encode, decode and take apart URLs and query strings.
- JWT DecoderRead the header, payload and expiry of a JSON Web Token.