Skip to content
GoWebTools

SQL Formatter and Beautifier

Format SQL queries with keyword casing and one clause per line. Makes long joins and filters readable. Free online SQL beautifier.

On your device: nothing you enter here is uploaded.

Input

Result

The result appears here as you type.

What this tool is for

A query pulled from an application log is one long line with four joins in it. Formatting puts each clause and each selected column on its own line, which is usually enough to see the mistake without opening a database client.

What formatting changes, and what it never does

The formatter only changes whitespace and, if you choose, the case of keywords. It is meant for reading and reviewing queries, not for rewriting them: spacing inside string literals can be collapsed and a single-line -- comment can swallow the code that follows it once lines are joined. Format a copy to understand it, and keep running the original.

Each major clause, SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY, starts on a new line and selected columns are listed one per line, which is usually enough to see the shape of a long query at a glance.

Conventions that make SQL easier to read

Uppercase keywords and lowercase identifiers separate the structure of a query from its names at a glance. One column per line makes diffs in code review show exactly which column changed. Put each join condition next to its JOIN, not in the WHERE clause, so it is obvious which table each condition belongs to.

Give every table in a join a short alias and prefix every column with it. Without that, a query reads fine until someone adds a column with the same name to another table, and then it breaks with an ambiguous column error.

Finding the bug in a long query

Once formatted, the usual suspects are easy to spot: a LEFT JOIN quietly turned into an inner join by a condition on the joined table in WHERE; an OR without parentheses next to an AND, since AND binds tighter; a GROUP BY missing a column that appears in SELECT; and NOT IN against a subquery that can return NULL, which makes the whole condition return nothing.

How to use it

  1. Paste the SQL query.
  2. Choose keyword casing: uppercase keywords are the common convention.
  3. Copy the formatted query.

Frequently asked questions

Is my query sent anywhere?

No. Formatting is local, which matters because queries in logs often contain real values from production data.