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

Paste 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

Use the 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. The 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 your code

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 handled
MySQL / MariaDBBackticks, # comments, ON DUPLICATE KEY UPDATE
PostgreSQL::, ->>, $1, $$ dollar 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 restructured.

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.

Compare text online (Diff Checker)

Compare text online: Compare two texts, configs, or code versions, see differences line by line and word by word, and copy them as a Unified Diff. Runs entirely in your browser.

Built by Dimitri Heissler

JSON Formatter

Format, minify, and validate JSON with syntax highlighting, error messages, and downloads, entirely in your browser.

Built by Jakub Martyniak

XML Formatter & Validator

Validate, format, minify, and automatically repair XML (unescaped characters, missing tags, missing declaration)—100% in your browser, without uploading.

Built by Justin Schuessler

YAML Validator

Check YAML syntax and format it consistently or convert it directly to JSON. Supports multiple documents separated by `---` (e.g., Kubernetes manifests), with precise line and column error messages. Runs entirely in your browser.

Built by Jakub Martyniak

Regex Tester

Test regular expressions live against the native JavaScript engine—with match highlighting, capture groups, and replace mode, all in your browser.

Built by Jakub Martyniak

.htaccess Generator & htpasswd Generator

Create Apache .htaccess and .htpasswd files online: 301 redirects, HTTPS, password protection with bcrypt, WordPress rules, error pages, caching, GZIP, and hotlink protection. Runs entirely in your browser.

Built by Dimitri Heissler

Was this tool helpful?

Your feedback helps us prioritize and improve content.

FAQ

Frequently asked questions

Quick answers about the SQL Formatter.

What is an SQL Formatter or SQL Beautifier?

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.

Does the formatter change the meaning of my query?

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.

Which SQL dialects are supported?

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.

How do I minify SQL?

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.

Does the SQL Formatter check my syntax?

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.

Are my SQL queries uploaded?

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

Can I format a .sql file?

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.

Can I format multiple statements and placeholders?

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

Still have 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.6/5 Google32,000+ Active serversSince 2010

No setup. No risk. Online in 60 seconds.

Flexible TermCancel anytimeOnline in 60 seconds

Looking for more tools? View all developer tools