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.