SQL Formatter
Format SQL queries with proper indentation and optional keyword capitalization — now genuinely, powered by a well-tested, spec-aware SQL formatting engine instead of the previous hand-rolled implementation. A single-line query (the most common real-world shape — copied from a log, an ORM debug string, or application code) is now genuinely restructured into clause-per-line layout, subqueries are correctly indented as nested blocks, and CTEs (WITH) and window functions (OVER/PARTITION BY) are now recognized and formatted correctly.
No SQL query provided
How to Use This Tool
Paste your SQL query into the input textarea
a single dense line works fine now.
Toggle uppercase mode for SQL keywords if desired.
Toggle uppercase mode for SQL keywords if desired.
Pro Tip
Formatting doesn't touch query semantics — SQL parsers ignore whitespace entirely — so there's no risk in reformatting before debugging. The clause-per-line layout that surfaces a missing JOIN condition or a misplaced WHERE clause now genuinely appears for any query you paste in, dense single-line or not, without needing to manually restructure it first.
About This Tool
When to Use
- A developer reviewing a multi-table JOIN query with a subquery that's currently one unreadable line copied from a log file pastes it directly
- A technical writer formats SQL before pasting it into documentation, pasting the query exactly as copied without needing to manually pre-split it by clause first.
- A backend developer pastes auto-generated ORM output (Hibernate, Sequelize, Prisma)
Key Details
A SQL formatter is meant to turn a one-line, hard-to-read query into properly structured SQL — major clauses like SELECT, FROM, and WHERE on their own lines, JOIN conditions and subqueries indented as...
Worked example
Someone pastes the single-line query SELECT u.name,o.total FROM users u JOIN orders o ON u.id=o.user_id WHERE o.total>100 ORDER BY o.total DESC exactly as copied from a log file. The tool now genuinely restructures it: SELECT and its columns on their own lines, FROM users u on the next line, JOIN orders o ON u.id = o.user_id below that, then WHERE and ORDER BY each getting their own line — exactly the clause-per-line result a SQL formatter is supposed to produce, with no manual pre-splitting required.
Interpreting your result
The formatted output now genuinely reflects clause-per-line restructuring for any input layout — a single dense line and a pre-split query both produce the same correctly-indented result. The statement count and keyword badges remain reliable, and now also correctly recognize WITH, OVER, and PARTITION BY.
SQL Formatter FAQ
Does this tool actually reformat a single-line SQL query into multiple indented clause lines?
Yes, now genuinely — this was previously a confirmed bug where the formatter only checked whether an existing line of input started with a clause keyword, never scanning within a line for where one clause ends and the next begins, so a single-line query (including the exact placeholder example shown in this tool's own input box) came back unchanged aside from one added indent step. That's fixed: the formatter now genuinely tokenizes the query's actual structure, so a single dense line is correctly restructured into SELECT/FROM/WHERE/JOIN lines regardless of how it was originally laid out.
What SQL dialects are supported?
The formatter recognizes standard ANSI SQL keywords common to MySQL, PostgreSQL, SQLite, SQL Server, and Oracle: SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, ALTER, JOIN types, and aggregate/comparison keywords — plus, now fixed, WITH (CTEs) and window function syntax (OVER, PARTITION BY), which previously received no clause-aware treatment at all and are now formatted correctly.
Should I uppercase SQL keywords?
Uppercasing SQL keywords (SELECT, FROM, WHERE) is a widely-adopted convention that improves readability by visually separating SQL commands from table/column names. This is optional, can be toggled on/off, and works correctly on any input regardless of line layout.
How are subqueries formatted?
With genuine nested indentation now — this was previously a confirmed bug where the indentation depth used for clause lines was fixed and never increased for content inside parentheses, so a subquery never visually stood out from its parent query. That's fixed: a subquery is now correctly indented one level deeper than the query that contains it, whether it started on its own line or as part of a single dense line.
Can I format multiple SQL statements at once?
Yes — multiple statements separated by semicolons (respecting semicolons inside quoted strings) are correctly detected and counted, and each is formatted independently, useful for a migration file or schema script. Each statement now gets genuine clause-per-line restructuring, not just the pre-split ones.
Is it safe to use the formatted SQL directly in production?
Yes — formatting only ever changes whitespace, never the query's tokens or logic, so the output remains functionally identical to the input. Always test any query, formatted or not, in a staging environment before production use as standard practice.
Master Your Entire Toolkit
Access 500+ specialized calculators and tools designed for precision. No sign-up required, 100% free.
Built and reviewed by the Toolzip Team · Based on ISO/IEC 9075 SQL Standard