SQL Formatter
Free online sql formatter for developers. Format and beautify SQL queries. Fast and private.
Embed this tool
Copy and paste the code below into your website to embed this tool for free. An attribution link to The Util Box is required.
<iframe src="https://www.theutilbox.org/embed/sql-formatter" width="600" height="500" frameborder="0" style="border: none; max-width: 100%;" title="Free SQL Formatter tool from The Util Box"></iframe> <!-- Free tool by The Util Box — https://www.theutilbox.org/tools/sql-formatter --> <a href="https://www.theutilbox.org/tools/sql-formatter">SQL Formatter by The Util Box</a>
Frequently Asked Questions about SQL Formatter
SQL Formatter — Uppercase Keywords and Break Them Onto Lines
This SQL formatter is meant to take a dense query and make it readable: keywords in upper case, and a line break before each major clause.
Read the limitations below before you use it on a real query — it has a significant problem with SQL keywords.
What It Does — and the Problem It Has
The formatter works in three passes: it strips a long list of English words, it uppercases SQL keywords, and it puts a line break before the major clauses.
The problem is the first pass. The list of words it removes includes from,
and, or, in, on, as,
to, of, by, all, not and
into — and because the match is case-insensitive, the uppercase forms go too. So
FROM, AND, ON,
AS and BY are all removed from your query.
In practice SELECT id FROM users WHERE id = 1 AND active = true comes back as
SELECT id, name users id = 1 active = true — the FROM, the WHERE and the AND
are gone. Do not run this on a query you intend to execute.
Other Limits
- String literals are not protected. A word inside a quoted value that happens to be in the removal list is deleted from your data too.
- Identifiers are uppercased indiscriminately, so a column named
from_datedoes not match the pattern and survives, but one namedtoorallwill be stripped. - Only the main clause keywords get a line break, and the break points are a fixed list rather than the structure of your query.
- Nothing is validated. The formatter does not parse SQL and cannot tell you that a query is broken — it only rearranges text.
Related Developer Tools
- Diff Checker — compare the output with the original to see exactly what changed.
- Code Minifier — strip the whitespace out of a query instead.
- JSON to CSV — for getting query results into a spreadsheet.
- XPath Tester — the equivalent for XML queries.
- YAML Lint — for the configuration that usually holds a connection string.
- Regex Tester — for the patterns inside a WHERE clause.
- Cron Expression Generator — for the schedules around your queries.
- XML Validator — for the XML a query returns.
The formatting runs entirely in your browser — your SQL is never uploaded.