SQL Formatter
Paste a query and get it back readable, with every clause on its own line and the keywords in the case you like. Or squeeze it onto one line. Your SQL never leaves your device.
Ctrl+Enter to format
OUTPUT
Loading the formatter…
Why format SQL
A long query on one line is hard to review: you can't see where the joins end or which conditions belong to the WHERE clause. Putting each clause on its own line, with its columns and conditions indented below it, makes the structure visible at a glance. A consistent format also keeps diffs small when queries live in version control, because only the lines that really changed show up.
UPPER or lower case keywords
UPPER case keywords, as in SELECT name FROM users, are the classic style and make keywords stand out from table and column names. Many teams now prefer lower case because it reads more quietly. SQL doesn't care either way. Choose keep to leave the case as you typed it, for example to match the rest of a project.
How to format SQL
- 1
Paste your query
Paste one or more statements into the input pane, or press Sample to try a query with joins and a GROUP BY. The formatted version shows up next to it as you type.
- 2
Pick the dialect and style
Choose the database the query is written for, such as MySQL or PostgreSQL, so its own syntax is read correctly. Then set the keywords to UPPER, lower or keep them as written, and the indent to 2 or 4 spaces.
- 3
Copy, download or minify
Copy the result or download it as a .sql file. Switch to Minify to put the query on one line without comments, which is handy for logs and code strings. Press Ctrl+Enter to format the input itself.
Frequently asked questions
Which SQL dialects are supported?
Standard SQL, MySQL and MariaDB, PostgreSQL, SQLite and SQL Server (T-SQL). The dialect decides how quotes, comments and special operators are read. For example, backticks around names are MySQL, square brackets are SQL Server, and $$ quoting and ->> are PostgreSQL.
Does formatting change what my query does?
No. Only spaces, line breaks and, if you choose, the case of keywords change. Strings, names in quotes, numbers and comments are kept exactly as written, so the database runs the formatted query the same way.
What does Minify remove?
Line breaks, extra spaces and comments, so the query fits on one line. Comments have to go, because a -- comment on a single line would hide everything after it. Optimizer hints like /*+ INDEX(t i) */ and MySQL's /*! … */ comments are kept, because the database reads them.
Why do I get an error for a query that works?
The formatter reads the query to know where each clause starts. If the dialect is wrong, syntax from another database can look like a mistake, so first pick the dialect your query is written for. An error also appears for a real typo, such as a bracket or quote that isn't closed, with the line and column where it went wrong.
Is my SQL sent to a server?
No. Formatting runs in your browser, so table names, customer data in WHERE clauses and anything else in the query stay on your device.