SQL Formatter and Minifier - Read a Long Query
SQL formatter and minifier
What this tool does
The query you need to understand is rarely the one you wrote. It came out of a log, an ORM, a colleague's message - one line, four joins, a where clause you cannot find the end of. This page puts it on separate lines so the shape becomes visible, and puts it back on one line when something else has to read it.
How to use it
- 1 Paste the query - one statement or a whole script.
- 2 Pick your indent, then press Format or Minify.
- 3 The text changes in the same box - copy it, or press Undo.
A comment on one line is a hazard on none
A "--" comment runs to the end of the line. Minifying removes line breaks, so a comment left in place would swallow everything after it: the query still runs, it just quietly stops halfway. That is why minifying here strips line comments entirely - and why "--" inside a string stays exactly where it is, because there it is data, not a comment.
Quotes and doubled quotes
In SQL a quote inside a string is escaped by doubling it: 'O''Brien'. A tool that closes the string at the second quote reads the rest of your name as code, and from there every keyword it finds is imaginary. The same applies to quoted identifiers - `order`, "group", [limit] are names, and a keyword inside a name is not a keyword.
It never rewrites your query
Keywords are not uppercased, parentheses are not simplified, aliases are not renamed. Only whitespace moves. That matters because a formatted query usually goes back into a file that a team reviews: a diff full of case changes hides the one line that actually changed, and lowercase keywords are a house style, not a mistake.
Formatting is not checking
This page never connects to a database, so it cannot know whether a table exists, whether your join is right, or whether the query will be slow. It reads text and moves whitespace. What it does give you is the shape - and a query whose shape you can see is one you can reason about.