ToolsKit

SQL Formatter

Format SQL queries with proper indentation.

Reformat SQL into a more readable structure so clauses, joins, and expressions are easier to inspect and edit.

Loading the interactive tool… This page needs JavaScript to run the SQL Formatter.

How to use SQL Formatter

  1. Paste the data, code, token, or value you need to inspect.
  2. Set any format, encoding, or validation options.
  3. Run the tool and inspect the result or diagnostic output.
  4. Copy the output into your terminal, editor, API client, or project.

How SQL Formatter works

This formatter is a simple text rewriter, not a full SQL parser. It collapses whitespace, starts a new line before keywords such as FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, VALUES, SET, JOIN variants and UNION, and breaks after each comma with a two-space indent. It does not change keyword case or indent subqueries, so complex queries may need hand tidying.

Worked example

Input: select id, name from users order by name → Output: select id, then a line with two spaces and name, then a line starting from users, then a line starting order by name.

Common uses

  • Make a one-line query from a log readable before reviewing it.
  • Tidy a query pasted from an ORM debug output.
  • Put SELECT columns on separate lines so a diff shows which one changed.

Best for

  • reviewing complex queries
  • cleaning copied SQL
  • preparing SQL for documentation

Tips for better results

  • Validate the output before using it in production code.
  • Treat tokens, credentials, and secrets as sensitive even when processing happens locally.
  • For large payloads, keep an original copy so you can compare changes.

Frequently asked questions

Why format SQL?

Consistent indentation and uppercase keywords make long queries easier to read and review.

Does it change what the query does?

No, only whitespace and keyword case change.

Which dialects are supported?

Common SQL syntax used by MySQL, PostgreSQL, SQLite and SQL Server formats well.

Related tools

Explore tool categories