SQL formatter
Paste a query, pick your database, and get it back indented with one clause per line.
Runs entirely in your browser
- Input
- 0
- Output
- 0
- Change
- 0%
Input up to about 10 MB. It changes layout only: it does not run your SQL, check it against a schema or optimise it.
How to format a SQL query
- Paste the query into the box, or press Insert a sample to see how it works.
- Choose your database under Dialect, then set the keyword case and indent size.
- The formatted query appears below as you type. Copy it, or download it as a
.sqlfile.
Making SQL readable
A database reads a query the same way whether it sits on one line or forty, which is why queries pasted from logs, ORMs and monitoring tools so often arrive as a single unbroken string. Formatting puts each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) on its own line and indents the columns, conditions and subqueries beneath it, so you can see the shape of the query at a glance and spot a missing join condition.
The layout follows the dialect you pick, because the words and symbols differ between databases. A PostgreSQL cast such as price::numeric, a numbered parameter like $1, a MySQL backtick name, an Oracle CONNECT BY clause and a SQL Server TOP 10 are all valid in one dialect and a syntax error in another. Placeholders for bound parameters (?, $1, :name, @name) are recognised and left alone.
Keyword case has no effect on how a query runs, so it is purely a house style. A formatter that understands the grammar can change it safely, because it knows which words are keywords and which are column names or text inside quotes.
Tips
- Comparing a query before and after a change? Format both with the same settings and compare them in Text diff.
- Does the query return JSON columns? Paste a value into the JSON formatter to read it.
- Need to rename a table across a long script? Find and replace handles it before you format.
Questions
Is my SQL uploaded?
No. The formatting code is a script served from this site and loaded the first time you paste a query; the query itself stays in your browser and is not sent to any server.
Why does the dialect matter?
Databases add their own syntax. PostgreSQL has :: casts and $1 parameters, SQL Server has [bracketed] names and TOP, MySQL and MariaDB quote names with backticks, and BigQuery has its own array and struct forms. Picking the right one lets the parser accept your query. Standard SQL is the safe choice when you are unsure, but it is stricter about vendor extras.
Why do I see an error for a query that runs fine in my database?
The formatter reads the whole statement rather than just re-indenting lines, so an unclosed bracket or quote stops it, and so does syntax that belongs to a different dialect. The message gives the line and column where it gave up, and the most common fix is choosing the matching dialect.
Does formatting change what the query does?
Only whitespace and, if you choose, the case of keywords. String literals, quoted names and numbers keep their text, so 'select' inside quotes stays lower case when you pick UPPER CASE.
Can I format several statements together?
Yes. Statements separated by semicolons are each formatted, with a blank line between them.
Which keyword case should I use?
Either works; it is a style choice and databases ignore it. Upper case keywords are the older convention and make clauses stand out in plain text. Lower case is common in code bases that already use a linter or ORM output in that style. Keep as typed leaves your capitalisation alone.