Skip to content
Free tool

Online SQL Formatter – format and beautify SQL

Use the SQL Formatter to format and minify SQL online for MySQL, MariaDB, and PostgreSQL: one clause per line, indented JOINs and subqueries, and consistent casing for keywords such as SELECT and WHERE. Free with no sign-up required; your queries stay in your browser and are not uploaded.

Built by Luca Stanek

Query formatted? Run your MySQL or PostgreSQL database on a VPS with full control.

Formatted SQL

The formatted SQL will appear here once you paste something on the left.

Paste your SQL query on the left or load the example. The result appears instantly.

Your SQL queries stay in your browser: they are neither uploaded nor saved.

Example result

What this SQL Formatter does to your query

A query as it appears in code or a log, and the result with 2-space indentation and UPPERCASE keywords.

Input:

select c.id,c.name,count(o.id) as orders,sum(o.total) as revenue from customers c left join orders o on o.customer_id=c.id and o.status='paid' where c.created_at>='2024-01-01' and (c.country='DE' or c.country='AT') group by c.id,c.name having count(o.id)>0 order by revenue desc limit 10;

Result:

SELECT
  c.id,
  c.name,
  COUNT(o.id) AS orders,
  SUM(o.total) AS revenue
FROM
  customers c
  LEFT JOIN orders o ON o.customer_id = c.id
    AND o.status = 'paid'
WHERE
  c.created_at >= '2024-01-01'
  AND (c.country = 'DE' OR c.country = 'AT')
GROUP BY
  c.id,
  c.name
HAVING
  COUNT(o.id) > 0
ORDER BY
  revenue DESC
LIMIT 10;

Minified, for code, configuration files or logs:

SELECT c.id,c.name,COUNT(o.id) AS orders,SUM(o.total) AS revenue FROM customers c LEFT JOIN orders o ON o.customer_id=c.id AND o.status='paid' WHERE c.created_at>='2024-01-01' AND (c.country='DE' OR c.country='AT') GROUP BY c.id,c.name HAVING COUNT(o.id)>0 ORDER BY revenue DESC LIMIT 10;

This saves 44 of 332 characters (13 %) without changing the query.

How it works

How to format SQL online

Three steps, no account or installation required.

Step 1

Insert SQL

Paste your query, open a .sql file up to 2 MB, or load the example.

Step 2

Choose options

Select Format or Minify and the dialect (automatic, MySQL/MariaDB, PostgreSQL, or standard SQL). When formatting, you can also set the indentation (2 spaces, 4 spaces, or a tab) and keyword casing (UPPERCASE, lowercase, or unchanged).

Step 3

Apply result

Check the result and any notices with line and column numbers, then copy it or save it as a .sql file.

Two modes

Format or minify SQL

Both modes use the same input. You can switch between them with one click at the top of the tool.

Format: the SQL Beautifier

Makes long, single-line queries from code, logs, or ORMs readable: clauses on separate lines, indented JOINs, conditions, subqueries, CASE expressions, and CTEs. Statistics show the number of statements and lines, plus the detected dialect.

Minify: the SQL Minifier

Removes comments and unnecessary whitespace, for example from code, configuration files, or logs. Optimizer hints /*+ … */ and MySQL comments /*! … */ are preserved. Statistics show the character counts before and after, plus the percentage saved.

Rules

How the SQL Formatter formats

Clauses and lists

SELECT, FROM, WHERE, GROUP BY, and others go on separate lines, with one column or value per line.

JOINs and conditions

JOINs are indented under FROM; AND and OR start a new line in WHERE and ON.

Subqueries and CASE

Subqueries, WITH, and CASE are indented; the closing parenthesis aligns with the opening one.

Nothing changed

Names, text and comments stay the same; only the capitalization of keywords changes. Ambiguous words like status or date stay as you typed them.

Supported SQL dialects and their differences
DialectWhat’s taken into account
MySQL / MariaDBBackticks, # comments, ON DUPLICATE KEY UPDATE
PostgreSQL::, ->>, $1, $$-Quotes, ILIKE, RETURNING
Standard SQLSingle and double quotes, -- and /* */

Limitations: Syntax is not checked against a database; BEGIN … END and T-SQL or Oracle-specific features are not converted.

Not a replacement for FORMAT(): the formatter changes the layout of the query, not its values. To format a date, use a database function such as DATE_FORMAT() in MySQL and MariaDB or TO_CHAR() in PostgreSQL.

Discover more

More developer tools related to the SQL Formatter

Format JSON and XML, validate YAML, compare two versions of a query, or test regular expressions.

FAQ

Frequently asked questions

Quick answers about the SQL Formatter.

Both names refer to the same tool: an SQL Formatter lays out a query for readability, with one clause per line, indented JOINs, conditions, and subqueries, plus consistent keyword casing. Handy for queries from logs, ORMs, or dumps.

No. Only whitespace and the casing of unambiguous keywords, functions, and data types change. Names, numbers, strings, and comments stay as they are. Words such as status or date, which could also be column names, stay exactly as you typed them.

MySQL and MariaDB, PostgreSQL, and standard SQL. The dialect is detected automatically and shown when formatting; you can also select it manually. The formatter does not restructure T-SQL or Oracle-specific constructs or blocks such as BEGIN … END.

Select “Minify”. Comments and unnecessary whitespace are removed, while optimizer hints such as /*+ … */ and MySQL comments /*! … */ are preserved. Statistics show the character counts before and after and the percentage saved.

It does not check against a database: the query is neither executed nor fully validated. However, the formatter reports unterminated strings, quoted names, comments, and dollar-quoted strings with line and column numbers, warns about unclosed or extra parentheses, and takes you to the location when clicked.

No. Everything runs in your browser; nothing is uploaded or stored.

Yes. Use “Open file” to load .sql, .txt, .ddl, .psql, or .mysql files up to 2 MB. You can copy the result or save it as formatted.sql or minified.sql.

Yes. Semicolon-separated statements are formatted individually and separated by a blank line. Placeholders such as ?, :name, $1 and %s remain unchanged.

Any more questions?

Contact Support
Building something of your own?

Your database needs a reliable server

A ZAP-Hosting VPS reliably brings your application and database online.

4.4/5 Trustpilot32,000+ Active serversSince 2010

No setup. No risk. Online in seconds.

Flexible TermCancel anytimeOnline in 60 seconds

Looking for more tools? View all developer tools