Skip to content

SQL Formatter

Re-indent a SQL query into readable clauses, joins and conditions.

Quick Tool Overview

The SQL Formatter tokenises a query before laying it out, so a keyword inside a string or a column named "order" never confuses it. Clauses get their own lines, joins align, and subqueries indent while function calls stay inline.

What it does
Re-indents SQL into readable clauses
You give it
A query or a script of statements
You get back
Formatted SQL with clauses, joins and conditions laid out
Best for
Reading ORM-generated SQL and reviewing migrations
Developer Tools Free, unlimited use No sign-up Runs in your browser

About the SQL Formatter

A query copied out of an ORM log or an application string arrives as one long line, and reading it is guesswork. The formatter tokenises it properly and lays it out the conventional way: each major clause on its own line, the selected columns indented beneath SELECT, joins with their ON conditions aligned, and AND and OR under the WHERE they belong to.

Tokenising rather than pattern-matching is what makes it reliable. A string literal containing the word "from", a column named "order", a comment holding a semicolon — none of them confuse it, because the formatter knows what each token is before it decides where to break. Subqueries are indented as blocks while function calls stay inline, so count(o.id) is never split across two lines.

Key features of the SQL Formatter

Tokenised, not pattern-matched

String literals, quoted identifiers and comments are recognised as such, so the word "from" inside a string is never treated as a clause.

Subqueries indent, calls do not

A parenthesis holding SELECT becomes an indented block; one holding arguments stays inline, so count(o.id) is never split.

Conditions under their clause

AND and OR are indented beneath the WHERE they belong to, and ON sits under its JOIN, which is what makes a long query scannable.

Keyword case is yours

Upper case, lower case, or left exactly as written — and only reserved words are touched, never your column names.

Every dialect's quoting

MySQL backticks, standard double quotes and SQL Server brackets are all recognised as identifiers and left alone.

How to use the SQL Formatter

  1. 1

    Paste your SQL

    A single query or a script of several statements.

  2. 2

    Choose the keyword case

    Upper case is the convention; lower case and leave-as-is are also available.

  3. 3

    Set the indentation

    Two spaces, four spaces or a tab.

  4. 4

    Copy the result

    Paste it into your editor, a migration or a code review.

Frequently asked questions

The formatting is dialect-agnostic. MySQL backticks, PostgreSQL and standard double quotes, and SQL Server square brackets are all recognised as quoted identifiers and left alone.

Reviews of the SQL Formatter

What people who use the SQL Formatter think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the SQL Formatter. It takes half a minute and no account.

Write the first review

More developer tools