Developer 🔒 Runs in your browser — no data sent to servers

SQL Formatter

Turn a one-line query into readable SQL, with each clause on its own line and keywords in the case you like.

Input
Output

Format SQL Online

Queries copied from application logs, ORM debug output or a colleague's message usually arrive as one long line. Reviewing or debugging them in that form is slow and error-prone. This page is the Code Formatter set to SQL, using the open-source sql-formatter library in your browser.

Before and after

The query select id, name from users where active = 1 and role in ('admin','editor') order by name is a typical one-liner from a log.

The formatted version puts SELECT, FROM, WHERE and ORDER BY each on a line of their own, lists id and name on separate indented lines under SELECT, and indents active = 1 and AND role IN ('admin', 'editor') under WHERE, so each condition can be read, commented out or changed on its own.

Why the dialect matters

SyntaxDialect
`backtick names`MySQL, MariaDB
[bracket names]SQL Server
value::integer castsPostgreSQL
LIMIT vs TOP vs FETCH FIRSTEach database has its own

Choosing the right dialect lets the formatter recognise these forms instead of treating them as errors.

Style tips

  • Uppercase keywords make the structure of a long query easy to scan; many teams require them.
  • One column per line makes diffs in code review show exactly which column changed.
  • Keep formatted SQL in version control, and minify only where a single line is required.

Related tools

To compare two versions of a query, use Text Compare. For JSON returned by a query, the JSON formatter makes it readable.