Menu

Tools

SQL Formatter
Format and beautify SQL queries with proper indentation
Loading...

About SQL Formatter

Turn messy, one-line SQL into properly indented, readable queries. The formatter handles SELECT, INSERT, UPDATE, DELETE, and complex joins with subqueries. Great for debugging and code reviews.

Whether you've copied a query from logs, generated SQL from an ORM, or inherited legacy code, this formatter cleans it up instantly. Works with MySQL, PostgreSQL, SQL Server, and standard SQL syntax.

How to use SQL Formatter

1

Paste your SQL query into the input area.

2

The formatter automatically beautifies it.

3

Adjust settings if needed (indent size, keyword case).

4

Review the formatted output.

5

Copy to use in your code or documentation.

Examples

Simple SELECT formatting

One-line queries become readable with proper indentation:

-- Before:
SELECT id,name,email,created_at FROM users WHERE status='active' AND role='admin' ORDER BY created_at DESC

-- After:
SELECT
    id,
    name,
    email,
    created_at
FROM users
WHERE status = 'active'
    AND role = 'admin'
ORDER BY created_at DESC

JOIN formatting

Complex joins are aligned for clarity:

SELECT
    u.name,
    o.order_id,
    o.total
FROM users u
INNER JOIN orders o
    ON u.id = o.user_id
LEFT JOIN payments p
    ON o.id = p.order_id
WHERE o.status = 'completed'

Subquery formatting

Nested queries are properly indented:

SELECT *
FROM users
WHERE id IN (
    SELECT user_id
    FROM orders
    WHERE total > 1000
        AND created_at > '2024-01-01'
)

Features

Proper indentation and line breaks
Uppercase SQL keywords
Align columns in SELECT clauses
Handle complex JOINs and subqueries
Support for multiple SQL dialects
Copy formatted output instantly

When to use this

  • Cleaning up auto-generated SQL from ORMs
  • Formatting queries before code review
  • Making log output readable
  • Standardizing team SQL style
  • Debugging complex queries
  • Documentation and tutorials

Common questions