How to use
- Paste your SQL into the input box, or press Load example.
- Choose the dialect that matches your database, the indentation and the keyword case.
- Press Format, then copy the result.
Examples
select id,name from users u join orders o on o.uid=u.id where u.age>18 and o.total>100 order by name limit 10
→ SELECT id, name FROM users u JOIN orders o ON o.uid = u.id WHERE u.age > 18 AND o.total > 100 ORDER BY name LIMIT 10PostgreSQL dialect, 2-space indentation, upper-case keywords.
SELECT 1 FROM t
→ select 1 from tWith the lower-case keyword option.
select (
→ Error: parse error at the end of the textBroken SQL is reported instead of being guessed at.
How it works
The query is read by the open-source sql-formatter library, which splits it into clauses and expressions according to the dialect you choose. Each major clause such as SELECT, FROM, WHERE and ORDER BY starts a new line, items in a list go on separate lines, and nested parts are indented by the amount you pick.
The keyword case option changes SELECT, FROM and the other reserved words. Names of tables and columns, and anything inside quotes, keep the case you typed.
If the text cannot be read as SQL in the chosen dialect, the tool shows the position of the problem instead of producing output.
Sources
Frequently asked questions
- Does this run or check my query?
- No. It only changes whitespace and keyword case. It reads the text to find clauses, but it never runs the query and does not know your tables, so it cannot tell you whether the query is correct for your database.
- Why does the dialect matter?
- Databases differ in syntax: MySQL quotes names with backticks, SQL Server with square brackets, and PostgreSQL has operators such as :: for casts. Choosing the right dialect lets the formatter read these correctly. If a query fails to format, try another dialect.
- Does formatting change what the query does?
- It should not. Only whitespace and the case of keywords change. Text inside quotes is left as it is. Still, compare important queries before and after, for example with a diff tool.
- Can it format several statements at once?
- Yes. Statements separated by semicolons are each formatted, with a blank line between them.
- Is my SQL uploaded?
- No. Formatting runs in your browser and the query never leaves it.