Result

Paste a SQL query to format it.

How to use this tool

  • Paste one or more SQL statements (separated by semicolons).
  • Choose the indentation and whether keywords should be uppercase.
  • Copy the formatted SQL.

How it works

The query is split into words, strings, quoted names, numbers, comments and symbols. Main clauses (SELECT, FROM, WHERE, GROUP BY, ORDER BY…) start new lines; columns in SELECT lists and conditions joined by AND or OR go on their own indented lines; JOINs and their ON conditions are indented; and subqueries in parentheses are indented one level further. Strings, quoted names and comments are never changed.

Example

A one-line query

select a, b from users u where u.active = 1 and u.age > 18 becomes

SELECT
  a,
  b
FROM
  users u
WHERE
  u.active = 1
  AND u.age > 18

Privacy and limitations

  • Everything runs in your browser; nothing you paste is uploaded or stored.
  • Works with standard SQL as used by MySQL, PostgreSQL, SQLite and SQL Server. Vendor-specific syntax is formatted on a best-effort basis.
  • The query is not run or validated against a database.

Frequently asked questions

Will formatting change what my query does?

No. Only whitespace and the case of keywords change; identifiers, strings and comments are kept exactly.

Does it support stored procedures?

Simple ones format reasonably, but procedural blocks (BEGIN…END, IF…ELSE) are not specially indented.