SQL Formatter
Format SQL for a selected dialect with a real parser-based formatter. Your work stays on this device whenever possible.
How to use SQL Formatter
- Paste a query into "SQL Query"; the placeholder shows a select against a users table.
- Choose a "Dialect": Standard SQL, MySQL, PostgreSQL, SQLite, SQL Server T-SQL, BigQuery or Snowflake.
- Set "Keyword case" (UPPERCASE, lowercase or Preserve), "Indent" (2 spaces, 4 spaces or Tab) and "Comma style" (Trailing or Leading).
- Press "Format SQL" and read the status line, which counts statements by semicolons and reports the output length.
- Press "Minify SQL" for a one-line version with comments removed, then use "Copy" or "Download .sql".
Worked example
Enter select id,name from users where active = true order by name; with PostgreSQL, UPPERCASE and 2 spaces. The library layout puts SELECT, FROM, WHERE and ORDER BY on their own lines, with the column list, table and condition indented beneath. The status line reads Formatted 1 SQL statement(s) as PostgreSQL, followed by the character count. Choosing Preserve would keep your lowercase keywords.
When to use this tool
- Making a long ORM-generated query readable before a code review.
- Shrinking a reporting query to one line to paste into a config value.
- Standardising keyword case across snippets written by different people.
Important limitations
Uses dialect-aware SQL grammar (PostgreSQL, MySQL, SQLite, Transact-SQL). Formatting normalizes syntax structure and spacing; it does not validate table schema, permissions, or query execution plans.
Frequently asked questions
Where does the formatting logic come from?
A formatter library fetched from a public CDN when you first press Format SQL. If that download fails, such as when you are offline, a basic fallback puts common keywords on new lines. The fallback does not indent by parenthesis depth or subquery and can alter keyword-like words inside string literals.
Does it check that my SQL is valid?
No. It reflows tokens and never contacts a database, so table names, permissions and logic are not checked. If the library raises an error, the plain fallback runs silently instead of showing a message.
Is Minify safe for every query?
Not always. It deletes everything after two dashes to the end of the line and collapses all whitespace, so a string literal with double spaces or two dashes is altered. Hash-style comments are left in place. Review queries containing text literals.
What does the Leading comma style do?
It moves commas to the start of continuation lines instead of the end, which makes commenting out one column easier and gives cleaner diffs. Only the library path honours it; the fallback ignores both comma style and dialect.
Why does the dialect matter?
Quoting and operators differ: backtick identifiers in MySQL, square brackets in T-SQL, double-colon casts in PostgreSQL. The right dialect helps the tokenizer keep those intact, while Standard SQL suits generic queries.