Skip to content
HNarzędzia
en
Categories

SQL formatter online - beautify and minify queries

Paste an SQL query to beautify it instantly - each clause on its own line, consistent indentation and keyword case - or minify it to a single line. Supports over a dozen dialects.

  • Free
  • No sign-up
  • Private
  • Runs locally

How to format an SQL query

  1. 1.

    Paste the query

    Paste SQL into the left box, open a .sql file or insert the sample.

  2. 2.

    Choose the dialect

    Pick your database (PostgreSQL, MySQL, SQL Server…) so that its specific syntax is recognised.

  3. 3.

    Set the style

    Choose keyword case (UPPER, lower, preserve) and indentation (2 spaces, 4 spaces or tab).

  4. 4.

    Copy the result

    Copy the formatted query or download it as a .sql file.

What well-formatted SQL looks like

A readable query puts each main clause on its own line (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY), indents columns and conditions by a fixed amount and writes keywords consistently - usually in upper case. This one-liner:

select id,name from users where active=1 and city='Boston' order by name

becomes:

SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
  AND city = 'Boston'
ORDER BY
  name

Formatting does not change what the query does: only whitespace and the case of keywords, functions and data types change. String literals and quoted identifiers stay exactly as they were.

Supported SQL dialects

DatabaseSyntax recognised only in that dialect (examples)
PostgreSQL$$…$$, ::int, RETURNING, ILIKE
MySQL / MariaDB`name`, # comments, LIMIT 10, 20
SQL Server (T-SQL)[Order Details], TOP 10, GO
Oracle (PL/SQL)CONNECT BY, :variable, BEGIN … END; blocks
SQLite, BigQuery, Snowflake, Redshift, Db2, DuckDB, ClickHouse, Trino, Spark, Hivetheir own functions and data types

Standard SQL mode handles ANSI syntax. If the query uses database-specific constructs and formatting fails, select the exact dialect.

Minify without breaking strings

Minify writes the query on a single line - handy when embedding SQL as a string in code, config files, logs or CI parameters. It collapses whitespace into single spaces and removes spaces around , ( ) ;, while keeping string literals, quoted identifiers, $$…$$ blocks and T-SQL [names] untouched. Comments are removed, or - if you keep them - -- comments become /* … */ so they do not comment out the rest of a one-line query. Optimizer hints /*+ … */ (Oracle, MySQL) and /*! … */ (MySQL) are always kept. Minify does not validate syntax.

Common causes of formatting errors

  • Unclosed quote - e.g. WHERE name = 'O'Brien'. Escape an apostrophe by doubling it: 'O''Brien'.
  • Another database's syntax - [column] is SQL Server, `column` is MySQL; Standard SQL mode may reject both.
  • Template placeholders - {{ var }} or ${id} are not SQL; replace them with a value such as 1 while formatting.
  • Incomplete fragment - a lone AND x = 1 without the start of the query is often unrecognisable.

On error you get the line, column and a code excerpt with a caret. For API responses, use the JSON formatter; to compare two versions of a query, try the diff checker.

Frequently asked questions

Are my queries sent to a server?

+
No. Formatting and minifying run entirely in your browser, so you can paste queries containing production table names and data.

Does formatting change what the query does?

+
No. Only whitespace and the case of keywords, functions and data types change. String literals and quoted names stay the same.

Should SQL keywords be upper or lower case?

+
SQL keywords are case-insensitive, so it is a convention. UPPER case (SELECT, FROM) is the most common because it separates syntax from table and column names.

Which dialect should I use for SQL Server?

+
Choose “SQL Server (T-SQL)”. It understands bracketed names, TOP, @variables and GO.

Why do I get an error when the query runs fine in my database?

+
Usually the selected dialect is too generic. Pick the exact database you run the query on. Template placeholders such as {{ variable }} also cause errors.

Can I format several statements at once?

+
Yes. Separate them with semicolons - each one is formatted separately, with a blank line in between.

Updated: