SQL Formatter Online Free
Paste any SQL query and get clean, readable, properly indented SQL instantly. Supports MySQL, PostgreSQL, SQL Server, Oracle, and SQLite. Runs entirely in your browser.
A hand-built SQL tokenizer that reformats, minifies, and case-normalizes your query
This formatter does not send your query to a server or a database driver to interpret. It runs a small character by character tokenizer written directly in JavaScript, splitting the raw SQL string into typed tokens, comments, strings, identifiers, numbers, punctuation, operators, and words, before reassembling them with consistent indentation. Nothing leaves your browser.
The tokenizer’s rules, in order
The scanner walks the input one character at a time and checks a fixed sequence of conditions at each position, always taking the first one that matches.
>=, <=, <>, and :: are checked before falling back to single-character operators.
Depth tracking and comma placement
An opening parenthesis increments a depth counter and a closing one decrements it, and every clause keyword and comma is indented by that current depth multiplied by your chosen indent string. This is what lets a subquery inside a WHERE clause end up indented one level deeper than the query around it, without the formatter needing to understand what the subquery actually does.
| Setting | Behavior |
|---|---|
| Indent width | Two spaces, four spaces, or a tab character, selectable and applied per nesting depth. |
| Comma placement | Trailing comma (comma then newline, the default) or leading comma (newline then comma-space), a stylistic preference some teams standardize on for cleaner diffs. |
| Newline before clause | When enabled, every clause keyword like FROM or WHERE starts on its own line. When disabled, the reconstruction still tokenizes and re-cases but keeps clauses inline. |
| Uppercase / lowercase | Rewrites every token whose uppercased form appears in a 70+ entry keyword list, covering clause words, joins, functions like COUNT and COALESCE, and constraint keywords, while leaving identifiers alone. |
Highlighting and stats
Syntax highlighting
A second, lighter pass colors keywords, function names, string literals, numbers, comments, and comparison operators for the highlighted view, using the same tokenization ideas but rendering spans instead of reformatted text.
Clause and table counts
The stats row counts clause keyword occurrences and counts identifiers following FROM or JOIN as a rough table count, both computed with simple regex matching over the formatted output.
Style guides and formatters
- ISO/IEC 9075 (SQL standard) is the base specification that most of these clause keywords trace back to, though every database vendor extends it differently.
- sql-formatter is the widely used npm library if you need dialect-aware formatting (Postgres, BigQuery, Spark, and more) with a real parser rather than a keyword tokenizer.
- SQL Style Guide by Simon Holywell documents the leading-comma and clause-per-line conventions this tool lets you toggle between.
- MySQL identifier quoting rules explain the backtick convention the tokenizer recognizes.
When formatting saves a code review
Cleaning up a query copied from a monitoring dashboard or slow query log before analyzing it, standardizing formatting across a team’s saved queries, uppercasing keywords in a script written by someone who typed everything lowercase, minifying a query before embedding it as a string literal in application code, and getting a fast visual read on how many joins and tables a query touches before you run it against production.
FAQ: SQL Formatter Online Free
Yes, completely free. No account, no signup, and no payment required.
No. All formatting happens in your browser with JavaScript. Your queries never leave your device. Safe to use with production queries and sensitive data.
The formatter works with Standard SQL, MySQL, PostgreSQL, SQL Server, and Oracle. Syntax for common functions, joins, window functions, and CTEs is recognized across all dialects.
Yes. The formatter handles nested subqueries, common table expressions, and window functions with proper indentation at each nesting level.
Minify removes all whitespace, line breaks, and comments to produce the most compact version of your SQL. Useful when embedding SQL in application code or configuration files.
In comma first mode, each new item in a SELECT list starts with a comma at the beginning of the line instead of the end of the previous line. Some teams prefer this style because it makes it easier to comment out individual columns during debugging.
Yes. Click UPPERCASE Keywords to convert all SQL keywords to uppercase, or lowercase keywords to convert them all to lowercase. The output is formatted at the same time.
From the blog
Deep dives on the things these tools touch
Minification, UUID collisions, diffing API responses, and the other questions that come up around this toolset.