SQL Formatter

Beautify and format SQL queries with proper indentation, keyword uppercasing, and clause-level line breaks.

How to use SQL Formatter

  1. 1

    Paste your SQL query into the Input panel.

  2. 2

    Click "Format SQL" to beautify it.

  3. 3

    Use "Minify" to compact the query into a single line.

  4. 4

    Copy or download the formatted output.

Frequently Asked Questions

Which SQL dialects are supported?

Standard SQL keywords work across MySQL, PostgreSQL, SQLite, and SQL Server. Dialect-specific constructs (PostgreSQL $$ blocks, MySQL backtick identifiers, T-SQL DECLARE) are formatted as-is without syntax errors.

Is my query sent to a server?

No — formatting is done entirely in your browser using JavaScript. Your SQL queries (which may contain sensitive schema or data) never leave your device.

Does formatting change how the query runs?

No — formatting only affects whitespace, case, and line breaks. The query logic, table names, column names, and values are not modified. The formatted output executes identically to the original.

Can I format stored procedures or complex multi-statement SQL?

The tool handles standard DML and DDL statements well. Very complex stored procedures with BEGIN/END blocks or procedural language (PL/pgSQL, T-SQL) may not format perfectly — it is optimized for standard SELECT/INSERT/UPDATE/DELETE queries.

What does "Minify" do for SQL?

Minify removes all whitespace and collapses the query to a single line — useful for embedding SQL in config files, URL parameters, or logging where whitespace waste is a concern.

Why are my column aliases or table names changed to uppercase?

The formatter uppercases SQL reserved keywords (SELECT, FROM, WHERE). If your table or column names happen to match a keyword (e.g. a column named "group" or "order"), wrap them in backticks or quotes.

Detailed Guide

SQL That a Human Can Review

ORM debug output. A copied query from a monitoring dashboard. Legacy stored procedures. All of them arrive looking like this:

SELECT u.id,u.name,u.email,o.total,o.created_at FROM users u INNER JOIN orders o ON u.id=o.user_id WHERE o.total>100 AND u.status='active' AND u.created_at>'2024-01-01' ORDER BY o.total DESC LIMIT 20 OFFSET 0

And after formatting:

SELECT
    u.id,
    u.name,
    u.email,
    o.total,
    o.created_at
FROM users u
INNER JOIN orders o
    ON u.id = o.user_id
WHERE o.total > 100
    AND u.status = 'active'
    AND u.created_at > '2024-01-01'
ORDER BY o.total DESC
LIMIT 20
OFFSET 0

Same query. The formatted version shows you the JOIN condition, the three WHERE clauses, and the sort order at a glance. The minified version requires counting commas to know there are five selected columns.


What the Formatter Does

Keyword uppercasing: SQL conventions (and many style guides) require keywords in uppercase. select, from, where become SELECT, FROM, WHERE — clearly distinguishing keywords from table and column names.

Clause-level line breaks: Each major clause (SELECT, FROM, JOIN, WHERE, AND/OR, ORDER BY, GROUP BY, HAVING, LIMIT) moves to its own line, creating a top-to-bottom readable structure.

SELECT-list indentation: When multiple columns are selected, each column appears on its own indented line — making it easy to see exactly what the query returns.

Subquery indentation: Inline subqueries inside parentheses are indented an extra level, visually separating them from the outer query.

Minify mode: Strips all indentation and line breaks to produce a single-line query — useful for embedding SQL in logs, string constants, or API payloads.


Supported SQL Dialects

The formatter applies standard ANSI SQL formatting rules, which work well across:

DatabaseCompatibility
PostgreSQL✅ Full support
MySQL / MariaDB✅ Full support
SQLite✅ Full support
Microsoft SQL Server (T-SQL)✅ Core SQL formatting
Oracle SQL✅ Core SQL formatting
BigQuery / Redshift✅ Most syntax

Dialect-specific procedural extensions (PL/pgSQL BEGIN...END blocks, T-SQL DECLARE, stored procedure syntax) may format imperfectly — the formatter handles standard SQL queries, not full procedural code.


When Developers and DBAs Use This

Debugging ORM queries: ActiveRecord, Hibernate, Elo...

Looking for a more detailed deep-dive and advanced tips?

Read Full Article on our Blog