SQL Formatter
Format or minify a query with a real scanner, so a keyword inside a string or a comment is left exactly as you wrote it.
Runs entirely in your browser
Loading tool...
How to use
- Paste a query — one statement or several.
- Choose how keywords should be cased and how far to indent.
- Format to read it, or minify to put it on one line for a log or a bug report.
- Copy or download the result.
Features
- Clauses, joins and conditions each on their own line, with subqueries indented.
- Never rewrites the inside of a string or a comment, including keywords.
- Understands quoted identifiers, so a column called "from" survives.
- Minify collapses a query to one line and drops comments, which cannot survive there.
Frequently asked questions
- Why does formatting need a parser at all?
- Because SELECT is a keyword in `SELECT id` and four ordinary letters in `WHERE note = 'select one'`. A formatter built from find-and-replace uppercases and line-breaks inside strings and comments, which changes what the query returns. This one splits the text into tokens first and only ever touches the ones that are keywords.
- Which dialect does it understand?
- The common core — the clauses, joins and operators shared by PostgreSQL, MySQL, SQLite and SQL Server, plus each of their identifier quoting styles. It formats rather than validates, so dialect-specific syntax it does not recognise is passed through untouched instead of being rejected or rewritten.
- Is my query sent anywhere?
- No. It is formatted by your own browser and never leaves the page, which matters because a real query names your tables and columns and often contains live values from your data. You can turn off your network connection and the tool still works.
Related tools
Format and beautify JSON instantly.
Strip comments and whitespace from a stylesheet without touching what is inside a string or a data URI.
Turn a JSON array into a spreadsheet, with columns taken from every record.