SQL Formatter

Format and beautify SQL queries with proper indentation

Input SQL

Formatted SQL

Formatted SQL will appear here

About this tool

SQL has a habit of arriving unreadable. Queries generated by an ORM come out as one enormous line, queries copied from application logs lose their formatting entirely, and queries written under time pressure accumulate joins and conditions until nobody can follow them. Formatting fixes this by putting each clause on its own line and indenting the structure - SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY - which turns a wall of text into something you can actually reason about. This matters more than aesthetics. A great many SQL bugs are structural: a join condition accidentally placed in the WHERE clause, a missing join that silently produces a cross product, an OR that needs parentheses and does not have them. All three are nearly invisible on one line and obvious once the query is laid out. Formatting only rearranges whitespace, so the query's behaviour is untouched. Everything runs in your browser, which matters because real queries contain table names and business logic.

How to use this tool

  1. Paste your SQLA single query or a whole script, however badly formatted it arrived.
  2. Format itClauses are placed on their own lines with consistent indentation and keyword casing.
  3. Read the structureCheck the joins and their conditions first - that is where most structural bugs hide.
  4. Copy it backTake the formatted query into your editor, migration or documentation.

Key features

  • Turns generated or logged SQL into something readable in one step.
  • Makes structural bugs visible - misplaced join conditions, missing joins, ungrouped OR clauses.
  • Consistent formatting makes code review and version diffs far more useful.
  • Runs in your browser, so schema names and business logic are never transmitted.
  • No account and no length limit.

Common uses

  • Reading a query pulled out of an application log or slow query report.
  • Cleaning up ORM-generated SQL to understand what it actually does.
  • Preparing a complex query for code review.
  • Debugging a query that returns too many or too few rows.
  • Standardising formatting across a repository of migrations and reports.

Tips for better results

  • Format before debugging, not after. Most structural mistakes become obvious the moment the clauses separate.
  • Check every JOIN has its ON condition. A join missing one produces a cross product, which usually shows up as a wildly wrong row count rather than an error.
  • Watch for OR inside a WHERE clause without parentheses - operator precedence means it rarely does what the author intended.
  • Format the query before pasting it into a bug report or a message to a colleague. It costs nothing and saves them the work.
  • Keep formatting consistent in version control so diffs show real logic changes rather than whitespace churn.

Mistakes to avoid

  • Assuming formatting changes behaviour. It only moves whitespace - the query plan and results are identical.
  • Debugging a one-line query rather than formatting it first, which hides exactly the errors you are looking for.
  • Leaving ORM-generated SQL unformatted in a bug report, making it far harder for anyone to help.
  • Reformatting an entire legacy file in the same commit as a logic change, so the diff becomes unreviewable.
  • Pasting production queries containing real table and column names into tools that upload them. This one does not.

Supported formats

  • SQL

Available options

  • Format
  • Indentation

Frequently asked questions

Paste your query above and it is reformatted with each clause on its own line and consistent indentation. Copy the result straight back into your editor.

Yes. No account, no query length limit and nothing uploaded.

No. Only whitespace, line breaks and indentation change. The logic, the execution plan and the results are exactly the same.

Yes for standard SQL structure, which is what formatting operates on - the clause keywords are shared across dialects. Highly vendor-specific extensions still format sensibly, just without dialect-specific rules.

No. Formatting happens in your browser, which matters because real queries expose table names, column names and business logic.

Indirectly, and it is one of the most useful things it does. Laying out the clauses makes misplaced join conditions, missing joins and unparenthesised OR clauses visible - all of which are effectively invisible in a single-line query.

Formatted, in version control - readability and reviewable diffs matter far more than a few bytes. Minified only makes sense when embedding a query in a constrained context.

Because it is written for a database to parse, not a human to read. Formatting it is often the quickest way to understand what your ORM query actually translated into, and why it might be slow.

People also search for

  • sql formatter online free
  • sql beautifier
  • format sql query online
  • sql pretty print
  • sql query formatter mysql
  • clean up sql code
  • sql indentation tool

Useful in

Related guides