SQL Formatter

Format SQL so each clause, join and subquery sits on its own line. Keywords can be uppercased, and strings and comments are left alone.

Use the tool

Why this tool exists

SQL written by an ORM, copied from a log or squeezed into one line by a colleague is hard to read, and mistakes in joins or conditions hide easily. A consistent layout makes a query reviewable.

The formatter starts SELECT, FROM, WHERE, GROUP BY, HAVING and ORDER BY on new lines, places joins and their ON conditions clearly, indents subqueries, and lays out VALUES lists. Keywords can be uppercased so they stand out from table and column names. Quoted strings, including escaped quotes, are kept exactly. It understands general SQL rather than one dialect, so very vendor-specific syntax may be laid out simply. Formatting runs in your browser, and your queries and table names are not uploaded.

How to use it

  1. Paste your SQL into the input box.
  2. Choose the indent: 2, 4 or 8 spaces, or a tab.
  3. Tick Uppercase keywords if you want SELECT and FROM in capitals.
  4. Copy the formatted query.

Frequently asked questions

Which databases does it support?

It uses general SQL rules and does not target one dialect. Common statements for PostgreSQL, MySQL, SQLite and SQL Server are laid out well, while vendor-specific syntax may be formatted more simply.

Does it change the meaning of a query?

No. Only whitespace, line breaks and the case of keywords change. String contents, identifiers and numbers are kept as written.

Can it format several statements at once?

Yes. Statements separated by semicolons, such as a SELECT followed by an INSERT, are each formatted in turn.

What about comments?

Comments are kept in the output. If you want to remove them, use the SQL Minifier, which strips comments and extra whitespace.