SQL Formatter
Formats SQL with configurable keyword case, indentation and comma placement, across major dialects.
Lays out a SQL query so you can read it — keywords aligned, clauses on their own lines, joins indented under the table they hang off. It knows five dialects, because the difference between them is mostly in how strings, identifiers and comments are quoted, and getting that wrong is how a formatter mangles a query.
ANSI quoting: double-quoted identifiers, and a quote inside a string written twice.
SQL in
Drop a .sql file
Read in this tab. Nothing is uploaded.
Formatted
In
253 byte
Out
0 byte
Statements
0
Tokens preserved
yes
This lays out SQL; it does not validate it. A query with a missing FROM will be formatted neatly and still rejected by your database.
How to use it
Pick your dialect first
MySQL backticks, PostgreSQL dollar quoting, SQL Server brackets — each changes what counts as an identifier and what counts as a string. Standard is the ANSI reading and is right for anything portable.
Set the house style
Keyword case, indent width, leading or trailing commas, and the width at which a select list wraps. Leading commas look strange until you have git-blamed a column list.
Check "tokens preserved"
The output is re-tokenised and compared to the input after every run. If it says no, the formatter has misread something — almost always a dialect mismatch — and you should use your input, not its output.
Common questions
Does it validate my query?
No. It lays SQL out; it does not know your schema and does not parse for meaning. A query missing its `FROM` clause will be formatted neatly and rejected by your database exactly as before.
Why were my `--` comments turned into `/* */`?
Only when minifying. A `--` comment runs to the end of its line, so putting the query on one line would comment out everything after it. The page counts how many were converted so the change is not silent.
What does "unterminated string" mean here?
A quote that never closes, usually because the dialect is wrong — a backtick in Standard mode, or a `$$` block in MySQL mode. Everything after it is read as part of that string, which is why the rest of the output looks scrambled.
Can I paste a whole migration file?
Yes — statements are split on semicolons and the count is shown. The formatting runs in a worker, so a large file does not lock the page, though a very long one will take a moment.
Feed it from
String Escaper
Escapes and unescapes strings for JSON, JavaScript, SQL, shell, CSV and regular expressions.
CSV to SQL
Generates CREATE TABLE and INSERT statements from a table, with inferred types and a chosen dialect.
JSON Formatter & Validator
Pretty-prints, minifies and validates JSON, pointing at the exact line and column of a syntax error.
YAML Formatter & Validator
Re-indents YAML consistently, validates it, and flags the tab and anchor mistakes that break parsers.
Next
These accept what this tool produces, so the result can go straight in.
SQL over CSV
Runs SQL against dropped CSV or TSV files in the browser — SELECT, WHERE, GROUP BY/HAVING, ORDER BY, LIMIT, CASE and a two-table JOIN — with the grammar on the page.
CSV to SQL
Generates CREATE TABLE and INSERT statements from a table, with inferred types and a chosen dialect.
List Formatter
Turns lines into a comma list, quoted SQL IN clause, JSON array or bullet list, and back again.
String Escaper
Escapes and unescapes strings for JSON, JavaScript, SQL, shell, CSV and regular expressions.
Base64 Encoder & Decoder
Encodes and decodes Base64 and Base64URL for text or files, handling UTF-8 correctly.
curl to Code
Converts a curl command into fetch, axios, Python requests, Go, PHP or PowerShell.