Turn a one-line SQL query into readable code: uppercase keywords, clauses on separate lines, indented.
No sign-up, no fees.
Turns one-line SQL into readable code.
Uppercase keywords, clauses on separate lines.
Subqueries and AND/OR are indented.
Leaves strings and comments alone.
What you type is processed, but never shared with anyone.
How to use the SQL formatter
The query you copied from a log is a single line and impossible to grasp at a glance. Three steps:
Paste the query. Put it into the SQL query box.
Adjust. Choose 2 spaces, 4 spaces or a tab for the indent; turn uppercase keywords on or off.
Copy. The formatted query appears below; take it with Copy.
What is SQL formatting?
SQL formatting makes a query easier to read without changing what it means: clauses like SELECT, FROM and WHERE move to their own lines, selected columns line up one per row and conditions are indented. In a long query that makes it easier to see which table is joined where. The database runs the query the same way; the difference is only for whoever reads it.
What you need to know
The tool only tidies the text; it doesn't run the query or validate its syntax.
Text in quotes ('hello') and comments (-- note, /* note */) is left alone; words inside them don't count as keywords.
The AND inside BETWEEN a AND b isn't split onto a new line.
Syntax specific to one SQL dialect may not format perfectly; check the result.
Tips
To tidy JSON embedded in a query, use the JSON formatter.
To try a regular expression, use the regex tester.