SQL Formatter
Beautify SQL queries with keyword highlighting and consistent clause indentation, entirely in your browser.
Use the tool ↓About this tool
SQL queries have a habit of arriving in one of two unreadable states: either compressed onto a single line by an ORM or query builder, or hand-written with inconsistent spacing after years of copy-pasting and editing. Either way, a query with several joins, a handful of conditions, and a subquery or two becomes genuinely hard to parse visually once it loses consistent line breaks and indentation — you end up re-reading it multiple times just to find where one clause ends and the next begins.
This formatter puts each major clause — SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, and their relatives — on its own line, which is the convention most SQL style guides converge on for a simple reason: it turns the query's logical structure into its visual structure. You can scan straight down the left edge and see exactly which table you're selecting from, which conditions filter it, and how it's grouped or ordered, without having to trace through a wall of text to find the boundaries between clauses. Keywords are capitalized and highlighted to reinforce that same structure at a glance.
Formatting a query is not the same as validating it against a specific database's dialect — MySQL, PostgreSQL, SQL Server, and SQLite all share the same core syntax (SELECT, FROM, WHERE, JOIN, and standard operators) but diverge in specifics like string-quoting conventions, date functions, and certain clause extensions (LIMIT vs. TOP, for instance). This tool works at the level of shared structure across dialects — clause layout, keyword casing, and consistent indentation — rather than attempting to parse or validate dialect-specific syntax, which means it formats queries written for any of the common SQL databases without needing to know which one you're targeting.
A note on what this tool intentionally doesn't do: it doesn't execute your query, connect to a database, or validate that table and column names actually exist — it's a pure text formatter, working from SQL's keyword and punctuation structure, the same approach the HTML, CSS, and JavaScript beautifiers in this hub take for their respective languages. Nothing you paste is sent anywhere; formatting happens entirely in your browser.
How to use it
Paste your SQL
A single-line query or an already-formatted one both work the same way.
Read the formatted result
Each major clause lands on its own line, with keywords capitalized and highlighted.
Copy the output
Copy the formatted query directly into your editor, migration file, or query tool.
Example
select id,name,email from users where active=1 and role='admin' order by name;
SELECT id, name, email FROM users WHERE active = 1 AND role = 'admin' ORDER BY name;
Common use cases
Reading ORM-generated queries
Format a compressed query logged by an ORM to actually understand it.
Code review
Format SQL consistently before comparing it in a pull request diff.
Writing migrations
Clean up a hand-written migration file's SQL for readability.
Debugging slow queries
Format a query pulled from a slow query log to study its structure before optimizing.
Documentation
Present a readable, consistently formatted query example in a doc or wiki.
Learning SQL
See how a compressed query breaks down clause by clause.