The Util Box

SQL Formatter

Free online sql formatter for developers. Format and beautify SQL queries. Fast and private.

Formatted
Paste SQL above

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_date does not match the pattern and survives, but one named to or all will 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

The formatting runs entirely in your browser — your SQL is never uploaded.