Skip to content

SQL formatter

Turn a one-line or messy SQL query into clean, indented code with consistent keyword case, for your dialect, or compress it back into a single line.

  • Free, no limits
  • No sign-up
Everything happens in your browser; your data is never uploaded.
  • ✓ Free
  • ✓ No sign-up
  • ✓ Nothing uploaded

Next step

What to do next

How to use it

  1. Paste your SQL query.
  2. Choose Format or Minify (one line).
  3. Pick the dialect, keyword case and indentation.
  4. Copy the result.
Try it now

What the formatter does

The formatter puts each major clause on its own line, SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, indents the column list and conditions, and applies consistent keyword case. For example:

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.active = 1 group by u.id, u.name order by orders desc limit 10;

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.active = 1
GROUP BY
  u.id,
  u.name
ORDER BY
  orders DESC
LIMIT
  10;

Multiple statements are separated by a blank line. Formatting is done by the open-source sql-formatter library (MIT license), running entirely in your browser.

Supported dialects

DialectNotes
Standard SQLGood default for most queries
MySQL, MariaDBBacktick identifiers, LIMIT, MySQL functions
PostgreSQL:: casts, RETURNING, dollar-quoted strings
SQL Server (T-SQL)TOP, square-bracket identifiers, GO
Oracle PL/SQLPL/SQL blocks, CONNECT BY
SQLiteSQLite syntax
BigQueryBacktick table paths, STRUCT, ARRAY
SnowflakeSnowflake-specific syntax

Picking the right dialect matters for vendor-specific syntax. If formatting fails with an error, check the dialect first, then look for an unclosed parenthesis or quote.

Options

  • Keywords: UPPERCASE (SELECT, FROM), lowercase, or as typed. Uppercase keywords are the most common convention because they separate SQL syntax from table and column names at a glance.
  • Indent: 2 or 4 spaces.
  • Minify (one line): removes comments and collapses whitespace, leaving strings and quoted identifiers intact. Useful for putting a query into a log message, a JSON field, a one-line config value or a command-line call.

SQL style tips

Formatting handles layout, but a few writing habits make queries easier to maintain:

  • Name your columns instead of SELECT *, so the query does not silently change when the table does.
  • Use short, meaningful aliases such as u for users and o for orders, and always qualify columns in joins (u.id, not id).
  • Prefer explicit joins (JOIN … ON …) over listing tables with commas and joining in WHERE.
  • Comment the why, not the what: -- exclude test accounts explains a condition better than repeating it.
  • One statement per purpose. Very long queries are often clearer as common table expressions (WITH … AS (…)), which the formatter lays out as separate blocks.

Why format SQL

  • Reading and debugging: a 40-line query is far easier to follow when each join and condition sits on its own line. Logical errors, like a condition in the wrong ON clause or a missing GROUP BY column, become visible.
  • Code review: consistent formatting keeps diffs small and focused on actual changes.
  • Documentation: formatted queries in tickets, wikis and runbooks are easier for teammates to reuse.
  • Queries from tools: ORMs, BI tools and query logs often produce long single-line SQL. Formatting it is the first step to understanding a slow query.

Privacy

SQL queries can reveal table structures, customer IDs or business logic. This formatter runs completely in your browser: the query is never sent to a server, stored or logged. It is safe to format queries from production systems.

The formatter does not connect to a database or run your query, and it does not check that tables and columns exist. It only changes whitespace and keyword case, so the meaning of the query stays the same.

Frequently asked questions

How do I format an SQL query?

Paste it, choose your dialect and keyword case, and copy the formatted result.

Which SQL dialects are supported?

Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery and Snowflake.

Why do I get an error?

Usually the dialect does not match the syntax, or a parenthesis or quote is not closed. Try another dialect or check the brackets.

Can I put a query on one line?

Yes. Choose Minify (one line) to remove comments and line breaks.

Is my query uploaded or executed?

Neither. It is formatted in your browser and never run.

Last updated: November 12, 2026

Recommended

Similar tools

If SQL formatter helped, you may need these too.

See all in category →

People also use