GIVE YOUR QUERIES ROOM TO READ

SQL Formatter.

Turn a dense query into SQL you can follow. Choose a dialect, set your style, and format in your browser.

QUERY WORKBENCHBrowser-only formatting · no SQL execution
Load an example
213 / 50,000 characters

02 Formatted SQL

Original query stays unchanged

An online SQL formatter for queries you need to read

SQL copied from application logs or a query builder often arrives as one long line. A SQL formatter, also called a SQL beautifier or SQL pretty printer, breaks that query into a readable structure. SELECT columns, JOIN conditions, filters and nested queries become easier to follow without manually adding every line break.

Paste a query into the input editor and choose your database dialect. Set two spaces, four spaces or tabs for indentation, then decide whether recognized keywords should be uppercase, lowercase or left as written. Select Format SQL to generate a separate result. The source remains available beside it for comparison.

For a quick workflow, press Ctrl+Enter on Windows or Linux, or Command+Enter on macOS. Copy the formatted SQL into your editor or download it as formatted.sql. If you edit the input or change an option, format again: the previous output is cleared so you cannot accidentally copy a result produced from different settings.

Choose the database your SQL was written for

SQL dialects share a common vocabulary but differ in keywords, quoting and extensions. A PostgreSQL formatter needs to recognize constructs that may not be interpreted the same way in MySQL or T-SQL. Choosing the right dialect helps the formatting engine read those differences.

DialectWhen to use it
Standard SQLPortable queries that use the common SQL syntax supported by the formatter.
PostgreSQLPostgres queries, including casts and positional parameters such as $1.
MySQL / MariaDBQueries using backtick identifiers and the selected database’s SQL vocabulary.
SQL Server (T-SQL)Queries with SQL Server conventions, such as bracketed identifiers and TOP.
SQLiteSQL written for SQLite rather than a server database dialect.
Oracle SQLOracle queries; this is not a stored-procedure formatter.
BigQuery / SnowflakeWarehouse queries written for the corresponding SQL dialect.

The dialect selector identifies the input language. It does not convert a MySQL query into PostgreSQL, replace unsupported functions or adapt a schema. Start with the dialect used by the database that will receive the query.

Three SQL formatting examples

These fictional examples are available above the editor. Loading an example also chooses its dialect. The outputs below use uppercase keywords and two-space indentation, so you can see the formatting before trying your own query.

01JOIN & aggregation

Group paid orders by customer and keep totals above a threshold. Formatting separates the join, filter and aggregate conditions.

SELECT
  c.id,
  c.name,
  count(o.id) AS order_count,
  sum(o.total) AS revenue
FROM
  customers c
  JOIN orders o ON o.customer_id = c.id
WHERE
  o.status = 'paid'
GROUP BY
  c.id,
  c.name
HAVING
  sum(o.total) > 1000
ORDER BY
  revenue DESC;

02CTE & window function

Rank orders within each customer using a PostgreSQL CTE and ROW_NUMBER. The nested SELECT becomes easier to follow.

WITH
  ranked_orders AS (
    SELECT
      id,
      customer_id,
      total,
      row_number() OVER (
        PARTITION BY
          customer_id
        ORDER BY
          created_at DESC
      ) AS position
    FROM
      orders
    WHERE
      created_at >= date '2024-01-01'
  )
SELECT
  customer_id,
  id,
  total
FROM
  ranked_orders
WHERE
  position = 1
ORDER BY
  customer_id;

03INSERT & comments

A MySQL insert with backtick identifiers, a comment, and a quoted value containing a semicolon. Text inside a string remains data.

-- Fictional seed data
INSERT INTO
  `products` (`sku`, `name`, `price`)
VALUES
  ('DEMO-01', 'Desk lamp; warm light', 29.95),
  ('DEMO-02', 'Reader''s notebook', 8.50);

Make review easier without mistaking layout for correctness

Consistent indentation makes it easier to follow a subquery or CTE. Separating SELECT columns and JOIN conditions helps a reviewer compare related expressions. In an aggregate query, distinct WHERE and HAVING sections make the two conditions easier to locate. Formatting supports that reading process; it does not decide whether the query expresses the intended business rule.

Keyword case is a style choice. This tool changes recognized keywords only when requested, leaving identifier, function-name and data-type case as written. It does not fill in parameters, rewrite joins, remove filters or connect to your database. Comments are retained, though the formatter may adjust their layout.

A neatly formatted query can still refer to a missing table, contain a type error or return unexpected rows. Database extensions and procedural scripts also exceed what a general formatter can handle. Review the result in context and use database-specific tooling for validation and performance analysis.

The formatting engine is SQL Formatter. Its documentation describes supported dialects and limitations, including stored procedures and custom delimiters. This page runs the engine locally with an input limit and a cancellable worker; it is intended for queries and manageable script excerpts.

SQL formatter: frequently asked questions

How do I format a SQL query online?

Paste your query, choose the SQL dialect used by your database, select indentation and keyword case, then click Format SQL. You can also press Ctrl+Enter or Command+Enter. Copy the result or download formatted.sql. Changing the input or settings clears the previous output until you format again.

Which SQL dialects can I choose?

The tool offers Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle SQL, BigQuery and Snowflake. Choose the source dialect so the formatter can recognize its quoting, keywords and syntax. Selecting another dialect does not translate the query for a different database.

Does formatting validate my SQL or make it faster?

No. A formatter rearranges whitespace and applies the keyword case you select. It does not check table names, column names, types, access permissions or query plans. A query that formats successfully may still be invalid or unsuitable for your database. Use your database tools to validate and investigate performance.

Is my SQL sent to a server?

Formatting runs in a Web Worker in your browser. The tool does not submit queries to a formatting API, connect to a database, persist your input or place it in the URL. SQL is only exported when you copy it or download the result.

Will uppercase keywords change my string values or column names?

The keyword option applies to recognized SQL keywords. This tool keeps identifier, function-name and data-type casing unchanged and does not substitute parameter values. Quoted strings remain data. Review the formatted result before using it, especially when the script uses database-specific extensions.

Can I format multiple SQL statements?

Yes. Separate ordinary statements with semicolons. The formatter adds spacing between them while handling semicolons inside recognized strings as part of the string. Custom delimiter commands, stored procedures and client-specific scripting are outside the supported workflow.

Why does my SQL fail to format?

First check the dialect and look for unmatched quotes or parentheses. Stored procedures, custom delimiters and template syntax such as Jinja or application-code interpolation may not be supported. Use plain SQL in the correct dialect. The tool limits input to 50,000 characters and stops a formatting job after ten seconds; split large scripts into smaller sections.

Are comments and placeholders removed?

The formatter retains SQL comments, although their spacing or placement may be adjusted. It does not replace supported dialect-specific placeholders with values. Some template or parameter syntaxes are not recognized, so choose the right dialect and review the output. Comments that disable SQL Formatter can leave a region unformatted.