Free Tool

SQL Formatter

Paste any SQL query to instantly format it with proper indentation, line breaks at every clause, and consistent keyword casing. Also minifies SQL for embedding in code. Works with MySQL, PostgreSQL, SQLite, SQL Server, and more.

SQL Formatter & Beautifier

Indent
Keywords

What the formatter does

  • • Puts each major clause (SELECT, FROM, WHERE, JOIN…) on its own line
  • • Indents column lists under SELECT, GROUP BY, and ORDER BY
  • • Places AND / OR conditions on separate indented lines inside WHERE / HAVING / ON
  • • Merges compound keywords: LEFT OUTER JOIN, GROUP BY, ORDER BY, etc.
  • • Preserves quoted strings and comments unchanged
  • • Works with SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, and more

Why format SQL?

Unformatted SQL is hard to read, review, and debug. Proper indentation, keyword casing, and line breaks make query structure immediately clear — especially for complex JOINs and subqueries.

Dialect note

This formatter targets standard SQL and works well with MySQL, PostgreSQL, SQLite, and SQL Server syntax. Some vendor-specific extensions may not format perfectly.

Before and after

A query like select u.id,u.name from users u join orders o on u.id=o.user_id where o.total>100 becomes a properly indented, keyword-uppercased, readable query.

How to use

  1. Paste your SQL query into the input area.
  2. Click "Format" to apply indentation and uppercase keywords, or "Minify" to compress the query.
  3. Copy the formatted SQL with the "Copy" button.

Frequently Asked Questions

What is a SQL formatter?
A SQL formatter (also called a SQL beautifier) takes compressed or poorly indented SQL and rewrites it with consistent indentation, line breaks at clause boundaries, and standardised keyword casing — making queries far easier to read and review.
Does this tool support MySQL, PostgreSQL, and SQL Server?
Yes. The formatter handles standard SQL syntax used across MySQL, PostgreSQL, SQLite, SQL Server (T-SQL), and Oracle. Dialect-specific syntax (e.g. PostgreSQL :: cast, MySQL backtick identifiers) is preserved unchanged.
Is any SQL sent to a server?
No. All formatting happens entirely in your browser using JavaScript. Your SQL queries are never transmitted or stored anywhere.
What is the difference between formatting and minifying SQL?
Formatting adds line breaks and indentation to make SQL human-readable. Minifying does the opposite — it strips all unnecessary whitespace to produce a compact single-line query, useful when embedding SQL in application code or configuration files.