SQL Formatter Online: Beautify a Messy SQL Query So You Can Actually Read It

You copy a query out of a log file, an ORM debug message or a colleague's chat, and it arrives as one endless line: select o.id,o.total,c.name from orders o join customers c on c.id=o.customer_id where o.status='paid' and o.total>500 order by o.total desc. It runs, but nobody can review it, spot the missing condition or explain it in a ticket. A SQL formatter fixes that in a second.
This guide shows how to beautify a SQL query online with the free SQL Formatter on DoraPDF, what the tool does to your text, where a simple SQL beautifier helps most, and the cases where you should still check the output by eye.
What the SQL Formatter does
The tool is intentionally simple. When you paste a query, it:
- Collapses all whitespace. Tabs, line breaks and double spaces are turned into single spaces, so you start from a clean line.
- Normalises keyword case. With UPPERCASE keywords ticked (the default), words like
select,from,where,left join,group by,order by,having,limit,insert into,update,set,case,when,then,else,end,distinct,like,between,is null,count,sum,avg,minandmaxbecome capitals. Untick it and the same keywords are written in lowercase instead. - Starts a new line for each main clause.
SELECT,FROM,WHERE,GROUP BY,ORDER BY,HAVING,LIMIT,JOIN,UNION,VALUES,SET,INSERT INTO,UPDATE,DELETE FROMandWITHeach begin a line. - Indents conditions and lists. Every
ANDandORmoves to its own indented line, and every comma is followed by a new indented line, so selected columns line up one per row.
The example above becomes:
SELECT o.id,
o.total,
c.name
FROM orders o
JOIN customers c ON c.id=o.customer_id
WHERE o.status='paid'
AND o.total>500
ORDER BY o.total DESC
Same query, same result, but now you can read it.
How to format SQL online (step by step)
- Open the SQL Formatter.
- Paste your query into the Input box. Formatting is live: the Output box updates as you type or paste.
- Choose UPPERCASE keywords on or off to match your team's style.
- Click Copy to put the formatted query on your clipboard, or Clear to start again.
- Paste the result into your editor, a pull request, a ticket or documentation.
There is no button to press and no limit on how many queries you format.
Why it helps: the benefits of formatted SQL
- Faster reviews. When each condition sits on its own line, a missing
AND deleted_at IS NULLor a wrong join key stands out immediately. - Cleaner diffs. One column per line means a change to the select list shows up as a one-line change in Git instead of a rewritten line.
- Easier debugging. You can comment out a single condition or join and rerun the query without hunting through one long string.
- Better documentation. Formatted SQL in a wiki page or a bug report is readable by people who did not write it, including non-developers checking a report.
- Consistent style. Upper-case keywords make the structure of the query visible at a glance and separate SQL words from table and column names.
Practical tips
- Format before you share, not after. Paste the formatted version into Slack, email or a ticket; it saves the reader a step.
- Pair it with other developer tools. If a query returns JSON, check it in the JSON Validator. If you need to load spreadsheet data, convert it with CSV to JSON. To test a
LIKEorREGEXPpattern on sample values first, use the Regex Tester. - Keep the original. The formatter changes spacing and keyword case only, but it is good practice to keep the raw query until you have run the formatted version once.
- Long IN lists. A query with
IN (1,2,3,...)will put each value on its own line because of the comma rule. That is handy for checking values, but you can join them back into one line in your editor if you prefer.
Common problems and how to fix them
Commas inside functions or strings are split too. The tool adds a line break after every comma, including inside COALESCE(a, b), ROUND(x, 2) or a string literal like 'Lahore, Pakistan'. The query still runs if the break is only whitespace outside a string, but a break inside quotes changes the value. Check string literals that contain commas and remove the extra line break before running.
A column name was capitalised. Some keyword words are also common column names, for example end, set, count or desc. Because the formatter matches whole words, a column called count will be shown as COUNT. Most databases treat identifiers case-insensitively, but if yours does not (or you use quoted identifiers), fix those by hand.
LEFT JOIN is split over two lines. With LEFT JOIN, RIGHT JOIN or INNER JOIN, the current version can put the first word on one line and JOIN on the next. The query still runs, since it is only a line break, but for neat output join the two words back onto one line.
Subqueries are not indented deeper. Nested SELECT statements get the same line breaks as the outer query but no extra indent level. For very complex queries with several levels of nesting, use the output as a starting point and indent the inner blocks yourself.
Comments disappeared into one line. Because all line breaks are collapsed first, a -- comment can swallow the rest of the query once everything is on one line. Remove single-line comments before formatting, or convert them to /* ... */ style.
It does not validate SQL. The formatter does not connect to a database or check syntax. A query with a typo will be formatted neatly and still fail. Run it in your database client to test it.
Privacy note
The SQL Formatter runs entirely in your browser. Your query, including table names and any values in it, is not sent to our server. You can safely format queries that reference internal schemas, but as always, avoid pasting real passwords or personal data into any tool you do not need to.
FAQ
Is this SQL formatter free? Yes. It is free, needs no sign-up and has no usage limit.
Which SQL dialects does it support? It works on plain text, so it handles the common keywords shared by MySQL, PostgreSQL, SQL Server, SQLite and Oracle. Dialect-specific words outside its keyword list are left as you typed them.
Can I beautify SQL in lowercase? Yes. Untick UPPERCASE keywords and the recognised keywords are written in lowercase while the line breaks stay the same.
Does it change what my query returns? It only changes whitespace and keyword case. The one thing to check is a string literal containing a comma, because a line break is added after that comma too.
Can I use it on my phone? Yes. It works in any modern mobile browser, which is useful when you need to read a query someone sent you in a chat.
Try it on your next query
Open the SQL Formatter, paste the messiest query you have, and copy back a version your team can review. For the rest of your toolkit, see the JSON Validator and Regex Tester.
Try the tools from this guide — free
Keep reading
Free Developer Tools Online: JSON Formatter, Regex Tester, Base64, URL Encoder, JWT Decoder, SQL and UUID
Eight small browser-based developer tools for everyday debugging: validate JSON, test regex, decode JWTs and Base64, format SQL, make UUIDs. Free.
GuideUUID Generator: Create Random v4 UUIDs (GUIDs) Online, One or a Thousand at a Time
Free UUID generator online: create random v4 UUIDs or GUIDs in bulk, uppercase or lowercase, and copy them in one click. Made in your browser.
GuideFree Online Tools for Web Developers and Designers: Why Many Keep DoraPDF Open in a Tab
Free online tools for web developers and designers in one place: JSON, regex, JWT, SQL, colours, gradients, SVG, WebP, breakpoints and link previews.