Skip to content

SQL Formatter & Beautifier - Format SQL Online

SQL input
Formatted SQL

Format SQL queries in your browser

Queries copied out of logs or ORM debug output usually arrive on one line. This formatter puts each clause on its own line, indents joins and subqueries, and gives every selected column its own row. Paste a query on the left and the formatted version appears on the right as you type.

Choose your SQL dialect

MySQL quotes identifiers with backticks, SQL Server uses square brackets and @variables, and PostgreSQL has the :: cast operator and $$ dollar-quoted strings. The parser only accepts the syntax of the dialect you pick: select a::int from t is a parse error under Standard SQL and formats fine under PostgreSQL. If you are not sure, start with Standard SQL and switch when you hit an error.

Keyword case and indentation

The keyword setting covers keywords, function names (count becomes COUNT) and data types. Preserve leaves them as you typed them. Table and column names are never re-cased. Indentation can be two spaces, four spaces or a tab.

How to use the SQL formatter

Paste a query (or use the Paste button), pick the dialect, then set keyword case and indent. The output updates on every change. Copy or Download takes the result back to your editor. A script with several statements separated by semicolons is formatted statement by statement with a blank line between each, which helps with migration files and seed scripts.

Example

Input:

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;

Output (MySQL, uppercase keywords, 2 spaces):

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;

Minify SQL to a single line

Minify does the reverse: one line, no comments. It removes -- and /* */ comments and collapses whitespace, but leaves the inside of quoted strings and identifiers alone, so 'a -- b' survives intact.

Tips

  • Commit SQL in formatted form. With one clause per line, a changed WHERE condition shows up as a one-line diff.
  • Placeholders follow the dialect: $1 under PostgreSQL, @id under SQL Server, :name under Oracle. ? works in most.
  • Need to tidy other code? Try the JavaScript beautifier or the XML formatter.

Related Tools

Frequently Asked Questions

Which SQL dialects are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL, DuckDB, ClickHouse, Trino, Db2 and Hive. The dialect decides which keywords, quotes and operators the parser accepts, so a query that fails in one may format fine in another.
Does formatting change what my query does?
No. The formatter only changes whitespace, line breaks and, if you choose, the case of keywords. Table names, column names, string literals and comments are left as they are.
Why do I get a parse error?
Usually the dialect is wrong. Standard SQL rejects [bracketed] identifiers (pick SQL Server), :: casts (pick PostgreSQL) and @variables (pick SQL Server). Other causes are an unclosed string or template placeholders such as {{name}}, which no dialect accepts. Swap them for ? or a plain value first.
What does minify do?
It strips -- and /* */ comments and collapses whitespace so the query fits on one line, for a log line, a JSON config or an environment variable. Single-quoted, double-quoted, backtick and [bracketed] text is kept as is. Minify ignores the dialect setting, and it does not recognise PostgreSQL $$ dollar-quoted bodies, so a -- inside a function body would be treated as a comment.
Is my SQL sent to a server?
No. Formatting runs entirely in your browser, so queries containing real table names or data never leave your machine.