SQL Formatter
Beautify and format SQL queries instantly. Supports standard SQL dialects.
What is SQL Formatting?
SQL queries are often written or generated as a single dense line — especially when copied from application logs, an ORM's debug output, or a database GUI's query history. That's efficient for storage and execution, but hard for a person to scan for a specific JOIN, WHERE condition, or column.
A SQL formatter (also called a SQL beautifier) solves this by breaking a query onto multiple indented lines, aligning clauses like SELECT, FROM, JOIN, and WHERE, and uppercasing keywords for consistency — without changing what the query does. Formatting only affects layout; the tables, columns, and logic remain exactly the same before and after.
Different database engines have subtly different SQL syntax, so a good formatter needs to be dialect-aware. This tool supports standard SQL, MySQL, PostgreSQL, SQLite, and T-SQL (Microsoft SQL Server), formatting each according to its own conventions.
This page lets you format SQL online for free, directly in your browser. Paste any query — from an app log, a migration file, or a BI tool — and it's instantly beautified or minified, all without installing anything or sending your data anywhere.
Why Format SQL?
Code Review
A consistently formatted query is far faster for a reviewer to scan for a missing JOIN condition or an unintended full table scan.
Debugging
Long queries generated by an ORM or copied from logs often arrive as a single line. Formatting makes it easy to trace which clause is causing unexpected results.
Query Optimization
Clear indentation of JOINs, subqueries, and WHERE clauses makes it easier to spot redundant conditions or a missing index opportunity.
Team Collaboration
Consistent casing and indentation across MySQL, PostgreSQL, SQLite, and T-SQL queries keeps a shared codebase readable regardless of who wrote each query.
Example
Here's the same query before and after formatting with 2-space indentation.
SELECT u.id, u.name, u.email, o.id as order_id, o.total, o.created_at FROM users u INNER JOIN orders o ON u.id = o.user_id WHERE u.active = 1 AND o.total > 100 ORDER BY o.created_at DESC LIMIT 20SELECT
u.id,
u.name,
u.email,
o.id AS order_id,
o.total,
o.created_at
FROM
users u
INNER JOIN orders o ON u.id = o.user_id
WHERE
u.active = 1
AND o.total > 100
ORDER BY
o.created_at DESC
LIMIT
20Features
Format
Beautify a single-line or messy query into clean, indented SQL with uppercase keywords.
Minify
Collapse formatted SQL back down to a single line for embedding in application code.
Copy
Copy the formatted or minified query to your clipboard with a single click.
Download
Save the result as a standalone .sql file for use in a migration or script.