🔒 Runs in your browser — nothing is uploaded✓ Free, no signup

SQL Formatter — Beautify SQL Queries Online

Turn long one-line SQL into readable, indented queries. Choose your database dialect, indentation and keyword case — or minify SQL back to one line.

Loading...

0 characters

Loading...

When should you use the SQL Formatter?

  • Reading a long query copied from logs, an ORM or a slow-query report
  • Cleaning up SQL before a code review or putting it in documentation
  • Minifying SQL to embed it in a config file or a single log line

How to use the SQL Formatter

  1. 1

    Paste your SQL

    Paste one or more statements into the input editor, or click Load sample.

  2. 2

    Choose the dialect

    Select your database so dialect-specific syntax such as T-SQL brackets or PostgreSQL :: casts is understood.

  3. 3

    Set indentation and keyword case

    Pick 2 spaces, 4 spaces or tabs, and whether keywords should be UPPERCASE, lowercase or kept as typed.

  4. 4

    Format or minify, then copy

    Click Format SQL for readable output or Minify for a single line, then use Copy Output.

Examples

One-line query to readable SQL

Before

select id, name from users where status = 'active' and age > 18 order by name

After

SELECT
  id,
  name
FROM
  users
WHERE
  status = 'active'
  AND age > 18
ORDER BY
  name

Common errors and how to fix them

Parse error at token
The selected dialect does not recognise some syntax. Switch to your actual database (e.g. PostgreSQL or SQL Server) and format again.
Template placeholders like {{id}} or :name break formatting
Replace them with a literal value or ? before formatting, then put the placeholders back.
Keywords used as column names become uppercase
Quote the identifier ("order", `order` or [order]) or set Keywords to 'Keep as typed'.
Related tools: JSON Formatter · CSS Minifier · JS Minifier

More from Code Formatters & Minifiers

Free tools that run in your browser — no signup, nothing uploaded.

SQL Formatter FAQ

Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), SQLite, Oracle PL/SQL, BigQuery, Snowflake, Redshift and Spark SQL. Pick the one that matches your database so dialect-specific syntax is recognised.

No. Only whitespace, line breaks and keyword case change. Table names, column names, string values and the query logic stay exactly the same.

SQL is case-insensitive for keywords, so it is a style choice. Uppercase keywords (SELECT, FROM, WHERE) are the most common convention because they stand out from table and column names.

The formatter could not understand part of the query. Usually the wrong dialect is selected (e.g. T-SQL brackets or PostgreSQL :: casts under Standard SQL), or the query is incomplete. Try switching the dialect.

Yes. Separate statements with semicolons and each is formatted with a blank line between them.

It removes comments and extra whitespace to put the query on one line, which is handy for logs, config files or embedding SQL in code. String literals are left untouched.