Developer tool

SQL Formatter

Paste a SQL query and format common clauses, indentation and keyword casing locally.

Runs in your browser. No upload.

About this tool

SQL Formatter made simple.

The formatter recognizes common SQL clauses, quoted strings and comments while adding readable line breaks and indentation. It is a best-effort formatter, not a parser, syntax validator or database connection; review the output before running it.

Guide

Using SQL Formatter

The SQL Formatter takes a pasted query and lays it out with line breaks and indentation, and it can turn common keywords into capitals. It works on the text only. It has no dialect setting and uses one generic set of rules for every query, so it is a best-effort tidy-up and not a parser. It never connects to a database, never runs your SQL and does not check that the query is correct.

How to use it

  1. Paste your SQL into the SQL query box. The limit is 200,000 characters, and an empty box shows an error message.
  2. Leave Uppercase keywords ticked to capitalise the keywords the tool knows, or untick it to keep your own capitalisation.
  3. Press Format SQL. The tidy version appears in the Formatted SQL box. Main clauses start on new lines, and commas at the top level start a new indented line.
  4. Read the result before you use it, then press Copy SQL. Clear empties both boxes.

Worked examples

A simple select

You enter
Sql
select id,name from users where active=1 and note='from where' order by name
Uppercase
yes
You get
Formatted
SELECT id, name FROM users WHERE active = 1 AND note = 'from where' ORDER BY name

Each main clause begins a new line. Spaces are put around the equals signs, and the text inside the quotes, including the words from and where, is left exactly as typed.

Run through the tool’s own code.

A join and a group, with capitals on

You enter
Sql
select u.id, count(o.id) as orders from users u left join orders o on o.user_id = u.id group by u.id order by orders desc limit 10;
Uppercase
yes
You get
Formatted
SELECT u.id, count(o.id) AS orders FROM users u left JOIN orders o ON o.user_id = u.id group BY u.id ORDER BY orders DESC LIMIT 10;

The line breaks are right, but the capitals are uneven. The first word of a two-word clause, left and group, stays lowercase while join and by are capitalised. This is how the code behaves today.

Run through the tool’s own code.

Quotes and comments, capitals off

You enter
Sql
select 'it''s' as s /* block */ from t -- end
Uppercase
no
You get
Formatted
select 'it''s' as s /* block */ from t -- end

The doubled quote inside the string is kept, and both comments are kept on their own lines. With the box unticked, none of the words are changed to capitals.

Run through the tool’s own code.

When it helps

  • Make a long one-line query readable before you read it or share it in a message.
  • Put a query into a consistent layout before adding it to documentation or code review.
  • Quickly spot the clauses of a query you did not write.
  • Tidy SQL copied out of logs without sending it to an online service.

Limits to keep in mind

  • There is no dialect choice. The code understands single-quoted strings, double-quoted and backtick names, square-bracket names, and both -- and /* */ comments. It has no special rules for any particular database product.
  • Things it does not know: backslash escapes inside strings, # comments, dollar-quoted blocks such as PostgreSQL function bodies, and nested block comments. Text in those can be mis-split or re-laid out, so check it.
  • Some operators and signs are spaced oddly. A negative number such as -1 becomes - 1, and the JSON operator ->> becomes -> >, which changes the text of the query.
  • Only the keywords it knows are capitalised, the list is short, and long queries with deep nesting, window functions or CASE blocks may get uneven indentation. It never runs or validates your SQL.

Tips

  • Read the formatted version once before running it. Compare it against the original if the query uses JSON operators, negative numbers or special string quotes.
  • Untick Uppercase keywords if your team writes keywords in lowercase, because that also avoids the half-capitalised joins.
  • Format a long script one statement at a time if it contains function bodies in dollar quotes, since those are not recognised.

Sources

Common questions

About SQL Formatter.

Which SQL dialects does it support?

It has no dialect setting. One generic set of rules is applied to every query. It reads the common quoting styles, including backticks and square brackets, and ordinary comments, but it has no knowledge of any single database's special syntax.

Does it run or check my SQL?

No. It never connects to a database and does not validate syntax. A wrong query stays wrong after formatting, and a correct one is not proven correct, so review the output before running it.

Does it change what my query does?

It aims only to change spacing, line breaks and keyword case. In a few cases it also alters spacing around signs, such as turning ->> into -> >. Compare the result with the original if your query uses such operators.

Why are some keywords capitalised and others not?

Only a fixed list of keywords is capitalised. In the two-word clauses LEFT JOIN, GROUP BY and PARTITION BY, the first word is not in that list, so it stays as you typed it. Untick the box to keep everything unchanged.

What happens to comments and strings?

Text inside single or double quotes and in -- and /* */ comments is kept as written. Doubled quotes such as 'it''s' work. A backslash before a quote does not, so a string like 'it\'s' can end early.

How big can the query be?

Up to 200,000 characters. An empty box, or text longer than that, shows an error message instead of output. The limit applies to the characters you paste, not to the number of statements.

Is my SQL uploaded?

No. The page states that the formatting runs locally in your browser. Even so, avoid pasting passwords or secrets into any text box.

What does an SQL formatter do?

It adds line breaks and indentation to common SQL clauses and can normalize recognized SQL keyword casing.

Does this tool validate or run SQL?

No. It is a best-effort formatter, not a syntax validator, database connection or security checker. Review the output before use.