KickSolve • Free • Private

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.

Subqueries and joinsKeeps strings and commentsNever uploaded

How to use SQL Formatter on KickSolve

Three quick steps, no account needed.

Paste your SQLPaste a query or open a .sql file. Formatting happens as you type.
Pick keyword case and indentChoose UPPERCASE keywords or keep them as typed, and an indent of 2 spaces, 4 spaces or a tab.
Copy or downloadCopy the formatted SQL or download it as a .sql file.

Why choose KickSolve

Built for speed, privacy and clean results.

Private by designEverything runs in your browser. What you paste or open is never uploaded or stored.
Instant, no signupFree to use with no account, no limits on how often you use it, and no software to install.
Only whitespace changesYour strings, comments, names and values are kept exactly. Only layout and optionally keyword case change.
Works across dialectsStandard SQL and common MySQL, PostgreSQL and SQL Server syntax lay out cleanly.

What you can do with SQL Formatter

Everything this tool is good for.

Reading long queriesBreak a one-line query into clauses you can follow.
Code reviewsPaste queries from pull requests to review them more easily.
Debugging ORMsFormat the SQL your framework logs to see what it really runs.
DocumentationPut consistently formatted SQL in docs and tickets.
Teaching and learningSee the structure of SELECT, JOIN and GROUP BY at a glance.
Stored scriptsTidy a batch of statements separated by semicolons.
Subqueries and CTEsSee nested queries indented under their parent.
Consistent styleApply the same keyword case across a team’s queries.

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 queryFormatting
SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMITStart a new line at the base indent
Columns in a listOne per line, indented
AND / ORNew line, indented under WHERE or ON
JOIN typesStart a new line, the ON condition is indented
Subquery in parenthesesIndented one level deeper
CASE ... WHEN ... ENDWHEN and ELSE on their own indented lines
SemicolonEnds 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.