SQL Formatter

Turn a one-line query into something you can read and review. Everything runs in your browser; nothing you enter is uploaded or stored.

  • Free, no sign-up
  • Runs in your browser
  • Verified

How to use it

  1. Paste your SQL.
  2. Choose indentation and whether to uppercase keywords.
  3. Copy the formatted query.

How it works

The query is split into strings, quoted names, comments, numbers, words and symbols, then laid out: each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, UNION, VALUES and so on) starts a new line, joins start new lines, AND and OR in WHERE, ON and HAVING go on indented lines, comma-separated lists are put one item per line, and subqueries are indented inside their brackets.

Only whitespace is changed (and keyword capitalisation, if you ask for it). Strings, quoted names and comments are copied byte for byte. Automated tests check this property on many queries, including thousands of random ones.

Examples

  • A one-line SELECT with a join, a filter and a GROUP BY becomes about ten readable lines.

Limitations

  • It is a general layout tool and not a parser for one SQL dialect. Unusual syntax (procedural code, vendor extensions) may be laid out in an odd way but is not altered.
  • It does not check that the SQL is valid.
  • Up to 1,000,000 characters.

Last verified . See our Accuracy & Editorial Policy. Found a problem? Email contact@tools.gift.