Skip to content

SQL Formatter

Beautify, indent, and clean up SQL queries instantly

0 characters

Clean Up and Beautify SQL Queries Instantly

SQL queries written under deadline pressure, pasted from ORMs, or extracted from application logs often arrive as dense single-line strings that are impossible to read. This formatter parses your SQL, identifies the clause structure, and rewrites it with consistent indentation, line breaks, and keyword casing. The result is readable, reviewable SQL that you can confidently share in code reviews, documentation, or support tickets.

How the Formatter Works

The formatter tokenizes the input into keywords, identifiers, strings, numbers, operators, and punctuation while preserving quoted strings and comments exactly as written. It then identifies major clause boundaries — SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, LIMIT, UNION, INSERT, UPDATE, DELETE, CREATE, and ALTER — and places each on its own line. Continuation elements like AND, OR, and comma-separated columns are indented under their parent clause. Parenthesized subqueries receive an additional indentation level.

Keyword Casing Conventions

The most widely followed convention writes SQL keywords in uppercase and table, column, and alias names in their original case. This visual separation makes queries scannable: your eye jumps to SELECT, FROM, and WHERE to understand the structure, then reads the identifiers for detail. The formatter supports uppercase, lowercase, and preserve-original modes so you can match whichever standard your team uses.

Formatting Complex Queries

Real-world queries are rarely simple. Multi-table joins, correlated subqueries, CASE expressions, window functions, and CTEs all benefit from structured formatting. The tool handles nested parentheses by tracking depth and indenting accordingly, so a subquery inside a WHERE clause is visually contained within it. JOIN conditions are kept on the same line as the JOIN keyword for compactness, and comma-separated select lists break into one column per line for easy scanning.

Minification for Embedding

Sometimes you need the opposite of formatting. Embedding SQL in code strings, logging queries in single-line formats, or passing them as URL parameters all require minimal whitespace. Minify mode strips comments, collapses all whitespace to single spaces, and removes unnecessary line breaks. The query stays syntactically valid but occupies the smallest footprint possible.

Privacy and Client-Side Processing

SQL queries often contain real table names, column names, and literal values that reveal your database schema and business logic. This formatter runs entirely in JavaScript inside your browser — no query text is sent to any server. That makes it safe to format production queries, debug output, and migration scripts without exposing your infrastructure to a third-party service.

$ faq

What SQL dialects are supported?
The formatter handles standard SQL syntax that works across MySQL, PostgreSQL, SQLite, SQL Server, and Oracle. It recognizes common keywords, clauses, joins, subqueries, and expressions from all major dialects. Dialect-specific syntax like MySQL backtick quoting and PostgreSQL double-dollar strings is preserved.
Does it change the meaning of my query?
No. The formatter only changes whitespace, indentation, and optionally keyword casing. It never modifies table names, column names, values, operators, or query logic. The formatted query is functionally identical to the original.
What does the keyword case option do?
It controls whether SQL keywords like SELECT, FROM, WHERE, and JOIN are converted to uppercase, lowercase, or left as-is. Uppercase is the most common convention and improves readability by visually separating keywords from identifiers.
Can I format multiple statements at once?
Yes. Separate statements with semicolons and the formatter processes each one independently. A blank line is added between formatted statements for clarity.
What does minify mode do?
Minify strips all unnecessary whitespace and collapses the query to the fewest characters possible while keeping it valid. This is useful for embedding SQL in code strings, log output, or URL parameters where compact size matters.
How are subqueries handled?
Subqueries inside parentheses are detected and indented one level deeper than the surrounding clause. Nested subqueries add another indentation level each time, so the visual structure mirrors the logical nesting of the query.
Is my SQL sent to a server?
No. All formatting happens in JavaScript inside your browser. Your queries never leave the page, making this safe for production SQL containing real table names, credentials in connection strings, or sensitive business logic.