SQL Formatter
Format SQL queries
Formatted entirely in your browser — your queries are never uploaded. Powered by the open-source sql-formatter library; supports the most common dialects' syntax.
About this tool
This free SQL Formatter turns cramped, minified or inconsistently written SQL into clean, readable, consistently indented queries in an instant. Paste a query — a sprawling JOIN-heavy SELECT, a stored procedure fragment, a migration script — and the tool lays it out with keywords capitalized and aligned, clauses broken onto their own lines, and nesting indented so the logic reads at a glance. Nothing to install, no account needed; formatting happens as you paste. Why does SQL so often arrive unreadable? Because it is written everywhere and formatted nowhere: generated by ORMs, logged by applications in one dense line, copy-pasted between teams, accumulated over years of edits. A 40-line query collapses into a single paragraph 800 characters wide, and the human who must understand it — to debug a slow query, to extend a report, to review a change — faces a wall of nested logic with no visual structure. Formatting restores the structure the logic already has: SELECT from WHERE, JOINs at consistent indentation, subqueries indented inside their parents, so the shape of the query matches the shape of its intent. Readable SQL is also faster SQL to fix. Performance tuning starts with reading: spotting the Cartesian join hiding in a missing condition, counting the subqueries that should be joins, finding the SELECT * that drags every column across the wire. Formatted queries make those patterns jump out; minified ones hide them. The same applies to code review and handover — a formatted query communicates; a dense one demands deciphering. Everything runs locally in your browser. Your SQL is parsed and formatted entirely by client-side JavaScript — nothing is uploaded, logged or stored on any server. Queries often embed table names, business logic and proprietary schema details you would rather keep on your device; you can format all of it with confidence, even offline once the page has loaded.
Frequently asked questions
How do I format SQL online with this tool?+
Paste your query into the input area — the formatted result appears live as you type, with keywords capitalized, clauses broken onto separate lines, and nesting indented consistently. Copy it with one click and take it back to your editor, documentation or migration script. Minified, single-line and sloppily-indented SQL all work as input; the tool normalizes whatever it receives into clean structure.
What does SQL formatting change — and what does it not touch?+
Presentation only: line breaks, indentation, keyword capitalization and spacing between clauses. Your query's logic is untouched — the same tables, joins, conditions and expressions, executing identically. Formatting cannot fix a wrong JOIN or a missing WHERE; it makes the query readable so *you* can find those. Formatting is also fully reversible: minify the result and you are back to compact form.
Why is my SQL query showing an error when I format it?+
The formatter expects syntactically plausible SQL — unbalanced parentheses, an unclosed string with a missing quote, or half-pasted query text can leave it unable to infer structure. Note that the formatter understands common SQL dialect patterns rather than validating against a specific database engine: it will format most standard queries across MySQL, PostgreSQL and SQL Server, but exotic vendor-specific syntax may pass through untouched rather than reformatted. Fix unbalanced quotes and brackets first.
Which SQL dialects does this formatter support?+
The formatter handles the shared core of SQL that all major engines speak — SELECT, INSERT, UPDATE, DELETE, JOINs, WHERE, GROUP BY, subqueries, CTEs — which covers the overwhelming majority of real queries. Dialect-specific extensions (PostgreSQL array syntax, SQL Server TOP, MySQL modifiers) generally pass through correctly since they ride on standard structure. For highly engine-specific constructs, the formatting is at minimum left intact rather than broken.
Does formatting SQL change how the query performs?+
No — formatting changes only how the query reads, never how it executes. The database engine parses identical logic either way; whitespace and capitalization are invisible to it. Formatting's performance value is indirect but real: a readable query lets you *find* the performance problems — the accidental cross join, the correlated subquery in a loop, the SELECT * dragging unused columns — that the minified version hides.
Does my SQL get uploaded to a server when I format it here?+
No. All formatting happens locally inside your browser using client-side JavaScript — your queries never leave your device, are never transmitted to any server, and are never logged or stored. After the page loads you can disconnect from the internet and the formatter keeps working. That makes it safe for queries embedding table names, schema details and business logic you would rather keep on your own machine.
Can I minify SQL too — the opposite direction?+
The formatted output is for humans; nothing about it prevents compact form for logs or storage. Formatting here is reversible by intent: you can strip the whitespace again when the query is headed somewhere machines read. The workflow mirrors the JSON trio: format while developing and reviewing, keep the compact form wherever bytes or log lines matter.
Is my formatted SQL still valid SQL for my database?+
Yes — formatting changes only whitespace and capitalization, both of which every SQL engine ignores when parsing. A formatted query executes identically to the original in MySQL, PostgreSQL, SQL Server, Oracle or SQLite. Keyword capitalization is convention, not requirement: SELECT and select parse identically — formatting simply adopts the readable uppercase convention that makes queries scannable.