SQL Formatter

Beautify or minify SQL queries for 20 database dialects. Runs in your browser.

Keywords
Indent
AND / OR
Input1 lines
Output
WITH
  recent_orders AS (
    SELECT
      customer_id,
      count(*) AS orders,
      sum(total) AS revenue
    FROM
      orders
    WHERE
      created_at >= DATE '2026-01-01'
    GROUP BY
      customer_id
  )
SELECT
  c.id,
  c.name,
  c.email,
  r.orders,
  r.revenue
FROM
  customers c
  LEFT JOIN recent_orders r ON r.customer_id = c.id
WHERE
  c.status = 'active'
  AND (
    r.revenue > 500
    OR r.orders >= 3
  )
ORDER BY
  r.revenue DESC
LIMIT
  20;
Standard SQL · 32 lines

How to format SQL online

  1. Paste a query or open a .sql file. The formatted version appears on the right as you type.
  2. Choose your database in Dialect so vendor syntax such as TOP, backticks or ::jsonb casts is recognized.
  3. Pick uppercase or lowercase keywords, 2 spaces, 4 spaces or tabs, and whether AND/OR start or end a line.
  4. Copy the result or download it as a .sql file. Minify puts the query on one line for logs, config files or code strings.

What a SQL formatter changes

A formatter rewrites layout, not logic. Each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) starts a new line, selected columns go one per line, joins line up under FROM, and nested subqueries and common table expressions are indented one level deeper. Keywords get a consistent case. Values inside quotes, comments and your table and column names are never altered.

Before

select id,name from users u join orders o on o.user_id=u.id where o.total>100 and u.active=1

After

SELECT
  id,
  name
FROM
  users u
  JOIN orders o ON o.user_id = u.id
WHERE
  o.total > 100
  AND u.active = 1

SQL formatting style guide

There is no single official style, but most teams settle on the same handful of rules. Simon Holywell's widely cited SQL Style Guide and the conventions built into this formatter agree on most of them:

  • Write reserved words in uppercase and identifiers in lowercase snake_case.
  • Put each selected column on its own line so changes show up as one-line diffs in version control.
  • Start every clause on a new line and indent what belongs to it.
  • Give every derived column and joined table a clear alias with AS.
  • Prefer common table expressions (WITH ... AS) over deeply nested subqueries.
  • Use explicit JOIN ... ON instead of listing tables separated by commas.

Supported SQL dialects

The SQL standard is ISO/IEC 9075 (the current edition is SQL:2023), but every database adds its own syntax. Choosing the right dialect matters most for quoting:

DialectQuoted identifiersTypical vendor syntax
MySQL / MariaDB`name`LIMIT, GROUP_CONCAT, # comments
PostgreSQL"name"::type casts, $$ ... $$ strings, RETURNING
SQL Server (T-SQL)[name] or "name"TOP (n), @variables, GO
Oracle PL/SQL"NAME"BEGIN ... END; blocks, :bind variables
BigQuery`project.dataset.table`STRUCT, ARRAY, QUALIFY
Snowflake"name"QUALIFY, : path access on VARIANT
SQLite"name", [name], `name`AUTOINCREMENT, PRAGMA

How to format SQL in SSMS, VS Code and Notepad++

SQL Server Management Studio gained a built-in formatter in version 22.7 (June 2026, preview), which became generally available in 22.10.2 (September 2026): right-click in the query window and choose Format SQL, or press Ctrl+K, Ctrl+Q, and adjust the style under Tools > Options > SQL Formatter. Older SSMS versions need an add-in such as Redgate SQL Prompt. VS Code has no SQL formatter out of the box; the SQL Formatter VSCode extension uses the same open-source engine as this page, after which Format Document (Shift+Alt+F on Windows, Shift+Option+F on macOS) works on .sql files. Notepad++ has no built-in SQL formatting either, so you need a third-party plugin from Plugins > Plugins Admin, or you can format the query here and paste it back.

When to minify SQL

Minify collapses a query to a single line: whitespace between tokens is reduced to one space, spaces around commas and parentheses are dropped and comments are removed. It is useful for embedding a query in a JSON config, an environment variable or a log line. Text inside quotes is kept exactly, so 'two spaces' stays as it is.

Formatting engine: sql-formatter 15.9.0 (released September 23, 2026), MIT License. Dialect notes checked against the MySQL identifier, PostgreSQL lexical structure and SQL Server database identifier documentation; SSMS versions from the SSMS 22 release notes. Checked October 2026.

Frequently asked questions

Is my SQL sent to a server?

No. Formatting and minifying run in your browser in a background worker. The query never leaves your computer, so it is safe for production queries and internal table names.

Does formatting change what the query does?

No. Only whitespace, line breaks and the letter case of keywords change. Table names, column names, string literals and comments are left as they are. Minify also keeps string literals and quoted identifiers intact.

Which SQL dialects are supported?

Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Amazon Redshift, Spark SQL, Hive, Trino/Presto, IBM Db2, DuckDB, ClickHouse, SingleStore, TiDB and Couchbase N1QL.

Why do I get a parse error?

The formatter has to understand the syntax of the chosen dialect. Pick the dialect that matches your database: backtick identifiers need MySQL or BigQuery, square brackets need SQL Server, and dollar-quoted strings need PostgreSQL. An unclosed quote or bracket also stops the parser at the line shown.

Should SQL keywords be uppercase?

SQL is case-insensitive for keywords, so it is a style choice. Uppercase keywords with lowercase identifiers is the most common convention in style guides because it separates the language from your schema at a glance.

Can I format several statements at once?

Yes. Paste a whole script; statements separated by semicolons are formatted one after another with a blank line between them.