SQL Formatter

How it works
Indent
Valid SQL

Input SQL

No problems found. This is valid SQL.

About SQL Formatter

Queries copied from logs, ORMs or a colleague’s chat message often arrive as one long line. Paste one here and it is laid out with SELECT, FROM, JOIN, WHERE and the other clauses on their own lines, columns listed one per line and keywords in uppercase.

Subqueries are indented inside their parentheses, which makes it much easier to see what a nested query is doing. Formatting happens in your browser, so queries that mention internal tables stay private.

How to use it

  1. Paste one or more SQL statements into the Input panel, or Open a .sql file.
  2. Choose an indent of 2, 4 or Tab; the formatted query appears on the right.
  3. If the query can’t be parsed, click the error in the Problems panel to jump to it.
  4. Copy the result or download it as a .sql file.

Frequently asked questions

Which SQL dialect does it use?

Standard SQL. Common syntax from MySQL, PostgreSQL, SQL Server and SQLite formats fine, but some vendor-specific statements may be reported as parse errors.

Does it change what my query does?

No. Only whitespace and the case of keywords change; table names, column names, strings and function names are left as written.

Can it format several statements at once?

Yes. Statements separated by semicolons are each formatted, with a blank line between them.

Related tools