SQL Formatter
Paste messy SQL, get clean readable queries — uppercased keywords, one clause per line, sensible indentation. Strings and comments are never touched. Free, private, no signup.
Dialect note: formatting is dialect-neutral — it works with standard SQL keywords from PostgreSQL, MySQL, SQLite, SQL Server, and others. Keywords are uppercased; your table and column names keep their original case.
How to format SQL
Unformatted SQL — the kind ORMs and query logs spit out — is one long line of mixed-case keywords that hides the query's shape. A formatter restores the shape: each major clause on its own line, consistent indentation, and keywords in a uniform case. The result reads top-to-bottom like the query actually executes.
- Paste your SQL above (or tap a sample query to see the formatter in action). It formats as you type — no button needed.
- Read the structure. SELECT lists break onto their own lines, JOINs and ON clauses separate, and subqueries indent inside their parentheses.
- Copy the result back into your editor or database client.
The formatting rules this tool follows
Keywords (SELECT, FROM, WHERE, GROUP BY, ORDER BY, JOIN, and dozens more) are uppercased; table and column names keep whatever case you wrote. AND and OR start new lines indented with the WHERE body. Commas in a SELECT list start new lines, but commas inside function calls or IN-lists stay inline. CASE..WHEN..END blocks indent like code. Multiple statements are separated with a blank line.
Why strings and comments are sacred
A naive formatter can corrupt a query by "fixing" text inside a string — imagine a keyword inside 'select from where' getting uppercased and re-indented. This formatter parses string literals and comments as opaque blocks first, then formats everything around them, so your data and notes come through byte-for-byte identical.
- What does a SQL formatter do?
- It takes messy SQL — one long line, mixed-case keywords — and rewrites it with consistent indentation and uppercased keywords so the query's structure is visible at a glance. It never changes what the query means.
- Will the formatter change my string values or comments?
- No. String literals and comments (-- and block comments) are parsed as opaque blocks and copied byte-for-byte, so text inside them — even text that looks like SQL — is never touched.
- Which SQL dialect does it support?
- The formatting rules are dialect-neutral and work with standard SQL keywords used by PostgreSQL, MySQL, SQLite, SQL Server, and others. It formats structure and casing, not dialect-specific syntax, so exotic vendor extensions pass through as plain text.
- Does it validate my SQL?
- No. This tool only reformats layout and keyword casing; it does not check that the query is valid or will run. Paste the formatted query into your database client to validate it.
- Why are some commas on new lines and others not?
- Commas at the top level of a clause (the SELECT column list) start new lines for readability; commas inside function calls like CONCAT(a, b) or IN-lists like IN (1, 2, 3) stay inline.
- Is my SQL sent anywhere?
- No. Formatting runs entirely in your browser with JavaScript. Nothing is uploaded or stored.
More from the codex
SQL Formatter
Clean, indented SQL with uppercased keywords.
JSON Formatter
Format, minify, and validate JSON.
Open tool → LiveJSON to CSV
Export JSON arrays as CSV.
Open tool → LiveRegex Tester
Test regular expressions live.
Open tool → LiveBase64 Encoder
Encode and decode Base64, URL-safe too.
Open tool → LiveURL Encoder / Decoder
Encode/decode URLs and parse query strings.
Open tool → LiveMarkdown Previewer
Live Markdown to HTML preview.
Open tool → LiveText Diff Checker
Compare two texts side by side.
Open tool → LiveUUID Generator
Random UUID v4 IDs, single and bulk.
Open tool → LiveHash Generator
SHA-256, SHA-512, and MD5 hashes online.
Open tool → LiveCron Explainer
Translate cron expressions to plain English.
Open tool → LiveCSS Minifier
Compress stylesheets online.
Open tool →Support the codex
This tool is free, with no account and no ads. If it saved you a trip to a search engine, consider supporting the indie dev behind it.
Questions about this tool?
Found a formatting bug or have a suggestion? Email [email protected] — every message is read by the indie dev behind the codex.