SQL Formatter
Paste a messy query and get clean, indented SQL. Joins, subqueries, CASE blocks and comments are laid out clearly. Your SQL stays in your browser.
How to use SQL Formatter on KickSolve
Three quick steps, no account needed.
Why choose KickSolve
Built for speed, privacy and clean results.
What you can do with SQL Formatter
Everything this tool is good for.
About SQL Formatter on KickSolve
What it does, how it works and how to get the best results.
What a SQL formatter does
It rearranges the whitespace of a query so each major clause starts on its own line and nested parts are indented. The meaning of the query does not change. Readable SQL is easier to review, debug and maintain.
What is formatted
Major clauses such as SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT and UNION each start a new line. Select lists are split by comma, AND and OR conditions are indented, JOIN types start new lines, and CASE blocks and subqueries in parentheses are indented.
Keyword case
UPPERCASE turns recognised SQL keywords into capitals, which is a common style. Keep as typed leaves your text alone. Table and column names are never changed.
Comments and strings
Line comments, block comments and quoted strings and identifiers are kept as they are, so values with keywords inside them are not touched.
Related tools
Working with exported data? Try CSV Viewer and Cleaner or JSON to CSV. For other formats see the JSON Formatter and XML Formatter.
Worked example: format a SQL query
One line in, readable query out.
Input: select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=1 and o.total>50 group by u.id,u.name order by orders desc limit 10; Output: SELECT u.id, u.name, COUNT(o.id) AS orders FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.active = 1 AND o.total > 50 GROUP BY u.id, u.name ORDER BY orders DESC LIMIT 10;
Each clause is on its own line, the select list is one column per line and the conditions are indented.
How SQL clauses are laid out
Where line breaks and indents go.
| Part of the query | Formatting |
|---|---|
| SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT | Start a new line at the base indent |
| Columns in a list | One per line, indented |
| AND / OR | New line, indented under WHERE or ON |
| JOIN types | Start a new line, the ON condition is indented |
| Subquery in parentheses | Indented one level deeper |
| CASE ... WHEN ... END | WHEN and ELSE on their own indented lines |
| Semicolon | Ends the statement and leaves a blank line |
Frequently asked questions
Quick answers.
How do I format a SQL query?
Paste the query into the box. The formatted SQL appears as you type. Choose your indent and keyword case, then copy or download it.
Does formatting change what my query does?
No. Only whitespace and optionally the case of keywords change. Names, values, strings and comments stay exactly as they are.
Which SQL dialects are supported?
It works with standard SQL and the common syntax of MySQL, PostgreSQL and SQL Server. It is a layout tool, not a validator.
Can it format subqueries, joins and CASE?
Yes. Subqueries are indented, each JOIN starts a new line and CASE blocks are laid out one branch per line.
Will it uppercase my table names?
No. Only recognised SQL keywords are changed, and only when UPPERCASE is selected.
Does it handle several statements?
Yes. Statements separated by semicolons are formatted one after another with a blank line between them.
Does it check that my SQL is valid?
No. It formats what you give it but does not run or validate the query against a database.
Is my SQL uploaded?
No. Formatting runs in your browser, so your queries never leave your device.
More free tools from KickSolve
Related free tools. Each one runs in your browser too.