SQL Formatter
Format SQL queries with each clause on its own line, indented column lists and nested subqueries. Keywords inside string literals are left alone, which naive formatters get wrong.
- Files never leave your device
- Free, no signup
- No watermarks
- Works offline once loaded
How to sql formatter
- 1
Paste your query
One long line, or something already half-formatted.
- 2
Set your preferences
Indent size, and whether keywords are uppercased.
- 3
Copy the result
Ready to paste back into your editor or migration.
The specific bug that trips up regex-based SQL formatters
A formatter that uppercases keywords by matching whole words with a regular expression has no way to know whether a given occurrence of "order" is the SQL keyword `ORDER` (as in `ORDER BY`) or a literal string value that happens to contain that word — a query filtering rows `WHERE description = 'the order from stock'` has the word "order" sitting inside a quoted string, not functioning as a keyword at all. A naive formatter uppercases every matching word regardless of context, corrupting the literal string value into `'the ORDER FROM stock'` and silently changing what the query actually filters for. Tokenising the query properly — recognising quoted string boundaries before deciding what counts as a keyword — is what prevents this, and it is precisely the class of bug that only surfaces on real data containing words that happen to collide with SQL keywords, which is why it is easy to miss in testing with simple example queries.
What "formats but does not parse" means in practice
This tool recognises the common clause structure shared across PostgreSQL, MySQL, SQL Server, SQLite and Oracle — SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY and their relatives — well enough to indent each clause onto its own line and nest subqueries correctly. It does not build a full understanding of any one database's complete grammar, including vendor-specific extensions like PostgreSQL's array syntax or SQL Server's `TOP` clause placement. The practical consequence is that dialect-specific syntax passes through the formatter untouched rather than causing an error, but it also will not receive the same careful indentation the common clauses do — a reasonable trade for supporting five dialects with one formatter rather than needing a separate tool per database engine.
Why formatting cannot change what a query does
SQL keywords are case-insensitive by the language specification itself — `SELECT`, `Select` and `select` are identical to every SQL engine — which is precisely what makes uppercasing or lowercasing them a purely cosmetic operation with zero risk of altering behaviour. The same is true of the whitespace and line breaks this formatter adds: a query spread across twelve indented lines executes identically to the same query jammed onto one. Nothing about formatting touches the actual tokens that determine what tables are read, what conditions filter rows, or what values get inserted — only how that same logical query is visually laid out for a human reading it afterwards.
Reading a long-running migration or generated query
A query generated by an ORM, exported from a database GUI, or written as a single sprawling line during a rushed migration is often functionally correct but genuinely hard for a person to review as written — a fifteen-join query with no line breaks makes it difficult to see which conditions belong to which join, or whether a WHERE clause is filtering the right table. Reformatting it with each clause and each join on its own line, indented to reflect the query's actual structure, is frequently the fastest way to actually understand what a long generated query is doing before approving it in a code review or debugging why it returns the wrong rows.
Frequently asked questions
Will it change what my query does?
No. Only whitespace and keyword capitalisation change — no clause is reordered and no token rewritten. SQL keywords are case-insensitive, so uppercasing them cannot alter behaviour.
What happens to text inside quotes?
It is left exactly as written. The formatter tokenises the query before touching anything, so a string like 'check the order from stock' keeps its lowercase "order" and "from" rather than having them uppercased as keywords. Regex-based formatters get this wrong routinely.
Which SQL dialects work?
The common clause structure shared by PostgreSQL, MySQL, SQL Server, SQLite and Oracle. It formats rather than parses, so dialect-specific syntax passes through untouched instead of causing an error — but it will not be specially indented either.
Are my queries sent anywhere?
No. Formatting happens in your browser. That matters because real queries carry table names, column names and sometimes literal customer data — none of which should be pasted into a stranger's server.
Common sql formatter tasks
You might also need
JSON Formatter
Format, validate and minify JSON instantly
JavaScript Formatter
Format JS and TypeScript with a real parser
XML Formatter
Indent XML and catch mismatched tags
Base64 Encoder & Decoder
Encode and decode Base64 and Base64URL
CSS Formatter
Beautify or minify stylesheets
CSS Minifier
Shrink stylesheets with a real CSS-aware minifier
Hash Generator
MD5, SHA-1, SHA-256, SHA-384 and SHA-512
HTML Formatter
Beautify and indent HTML properly