SQL Formatter & Beautifier

Free online SQL Formatter and Beautifier. Format PostgreSQL, MySQL, SQLite, and SQL Server queries with uppercase keywords, customizable indentation, and complete browser privacy.

SQL Formatter & Beautifier

Instant client-side SQL prettifier and minifier

Presets:
Indent:
Raw SQL Input
1 lines • 528 chars
Beautified SQL Query
36 lines • 601 chars
SELECT u.id,
  u.email,
  u.full_name,
  COUNT (
  DISTINCT o.id
) AS total_orders,
  COALESCE (
  SUM (
    o.total_amount
  ),
    0
) AS total_spent,
  MAX (
  o.created_at
) AS last_order_date
FROM users u
  INNER JOIN user_profiles up
  ON u.id = up.user_id
  LEFT JOIN orders o
  ON u.id = o.user_id
  AND o.status IN (
  'completed',
    'shipped'
)
WHERE u.created_at >= '2025-01-01'
  AND u.is_active = TRUE
  AND (
  up.country_code = 'US'
    OR up.country_code = 'CA'
)
GROUP BY u.id, u.email, u.full_name
HAVING COUNT (
  o.id
) >= 3
ORDER BY total_spent DESC, total_orders DESC
LIMIT 50;
Supports PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), and Oracle dialects.
100% Client-Side Privacy Guaranteed

Developer Scenario: Prettifying a Complex Multi-Table Analytics Query with Joins and CTEs

A database administrator extracts an unformatted, compact SQL query from application logs and formats it for debugging and indexing review.

Raw Input Querywith recent_orders as (select user_id,sum(total) as order_volume from orders where created_at>=now()-interval '30 days' group by user_id) select u.id,u.email,r.order_volume from users u inner join recent_orders r on u.id=r.user_id where u.status='active' order by r.order_volume desc limit 25;
Formatted SQL QueryWITH recent_orders AS ( SELECT user_id, sum(total) AS order_volume FROM orders WHERE created_at >= now() - interval '30 days' GROUP BY user_id ) SELECT u.id, u.email, r.order_volume FROM users u INNER JOIN recent_orders r ON u.id = r.user_id WHERE u.status = 'active' ORDER BY r.order_volume DESC LIMIT 25;

💡 The beautified query reveals the inner CTE structure and join conditions clearly, simplifying optimization and query plan analysis.

How to use SQL Formatter & Beautifier

  1. 1

    Paste your raw, messy, or single-line SQL query into the input editor, or select from database query presets.

  2. 2

    Choose your formatting options including keyword case (UPPERCASE or lowercase) and indent size (2 spaces, 4 spaces, or tabs).

  3. 3

    Click Beautify to neatly indent clauses, joins, and subqueries, or click Minify to compress the query into a compact single line.

  4. 4

    Copy the formatted SQL to your clipboard or download it as a .sql file ready for your database client or migration script.

Why use this tool?

Clean Syntax & Standardized Uppercase Keywords

Transform inconsistent casing into professional SQL convention with standardized keywords, indented clauses, and formatted column lists.

Multi-Dialect Compatibility

Works across PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle, Snowflake, and BigQuery without dialect incompatibilities.

Dual Beautifier and Minifier Modes

Beautify queries for readable git diffs and documentation, or minify them into single-line strings for environment variables and CLI scripts.

Frequently asked questions

Which SQL dialects are supported by this formatter?

It supports all ANSI SQL standards as well as popular dialects including PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server (T-SQL), Oracle, and Snowflake.

Does this tool transmit database queries or table schema to any server?

No. All tokenization, keyword capitalization, indentation, and minification run 100% locally in your web browser. Your table names, schemas, and queries never leave your machine.

Can this tool minify SQL queries for environment variables and migrations?

Yes. The Minify button collapses excess whitespace, strips single-line and multi-line comments, and produces a clean single-line SQL string ready for code or CLI execution.

Related tools

Developer Tools