Skip to content
SPCXTools

SQL Formatter

Turn long, messy SQL into clean, readable, consistently indented queries.

Runs locally — files never leave your device

Loading tool…

How to use SQL Formatter

  1. 1Paste your SQL query into the Input box, or click Sample to try an example.
  2. 2Pick your SQL dialect so database-specific syntax is recognised.
  3. 3Choose how keywords should look — UPPER, lower or as written — and the indentation.
  4. 4Copy the formatted query or download it as a .sql file.

Make SQL readable

Queries copied from logs, generated by an ORM or written in a hurry often end up as a single long line that's hard to read and even harder to debug. This SQL formatter breaks your query into clear clauses — SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY — puts each column and condition on its own line and indents subqueries and CASE expressions consistently. The result is easier to review, to compare in version control and to share with colleagues.

Features

  • 12 SQL dialects, from standard SQL to MySQL, PostgreSQL, SQL Server, Oracle, BigQuery and Snowflake.
  • Keyword case: UPPER, lower or exactly as written; applies to keywords, data types and functions.
  • Indentation with 2 spaces, 4 spaces or tabs.
  • Multiple statements separated by semicolons.
  • Comments preserved — both -- line comments and /* */ block comments.
  • Copy or download the result as a .sql file.
  • Private: the formatter runs locally in your browser.

Before and after

A query like this:

select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.status = 'active' group by u.id, u.name order by orders desc;

becomes:

SELECT
  u.id,
  u.name,
  COUNT(o.id) AS orders
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  u.status = 'active'
GROUP BY
  u.id,
  u.name
ORDER BY
  orders DESC;

SQL style tips

  • One clause per line. Starting each major clause on a new line makes the structure of a query visible at a glance.
  • Use meaningful aliases. Short aliases such as u and o are fine for small queries, but descriptive ones help in long reports.
  • Qualify column names in joins (orders.user_id rather than user_id) to avoid ambiguity.
  • Keep formatting consistent across a project so diffs show real changes, not whitespace.

Related tools

Working with query results? Convert exported data with CSV to JSON, pretty-print API responses with the JSON Formatter, or compare two versions of a query with the Diff Checker.

Frequently asked questions

Which SQL dialects are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, Google BigQuery, Snowflake, Amazon Redshift, Spark SQL and IBM Db2. Choosing the right dialect matters for database-specific syntax such as backtick identifiers, square brackets, dollar-quoted strings or special operators.
Does formatting change what my query does?
No. The formatter only changes whitespace, line breaks and, if you choose, the letter case of keywords, data types and function names. Table names, column names, strings and comments are left exactly as they are.
Why do I get an error?
The formatter needs to understand the structure of your query. Errors usually mean a typo, an unclosed quote or bracket, or syntax from a different database — try selecting another dialect. Templating placeholders such as {{ name }} can also confuse the parser.
Can I format several statements at once?
Yes. Separate statements with semicolons and each one is formatted, with a blank line between them.
Is my SQL sent to a server?
No. Formatting happens entirely in your browser, so you can safely format queries that contain internal table names or sample data.
Should SQL keywords be uppercase?
SQL is case-insensitive for keywords, so it's a matter of style. Uppercase keywords (SELECT, FROM, WHERE) are the traditional convention because they stand out from table and column names, while many modern teams prefer lowercase. Pick one and use it consistently.