Loona Automation logoLoona Developer Tools
Home › Developer Tools › SQL Formatter

SQL Formatter - Readable Queries, One Clause Per Line

In short: the SQL Formatter uppercases keywords, puts every major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT and each JOIN) on its own line, and indents AND / OR conditions - while leaving string literals exactly as written.

A one-line query with five joins is technically valid and practically unreadable. Paste it below and get the same query back in the layout you would write by hand on a good day.

Private by design: everything in this tool happens 100% in your browser with JavaScript. Your input is never uploaded to a server, never stored and never seen by us - close the tab and everything is gone.

How to use the SQL Formatter

  1. Paste your SQL query into the top box.
  2. Leave "Uppercase keywords" ticked for the classic look, or untick it to keep your original keyword case.
  3. Click Format SQL.
  4. Copy the formatted query or download it as a .sql file.

How it works

The formatter tokenizes your query first, so quoted strings, double-quoted and back-quoted identifiers are carried through untouched - a literal like 'select me' never gets uppercased or split. It then walks the token stream recognizing multi-word clauses such as GROUP BY, ORDER BY and LEFT OUTER JOIN, starts each major clause on a fresh line, and puts AND and OR conditions on their own indented lines. Spacing around operators and commas is normalized to the conventional single space.

Worked example

The one-liner select id, name from users where age > 18 and city = 'New York' order by name limit 10 becomes six clean lines - SELECT, FROM, WHERE, an indented AND, ORDER BY and LIMIT - ready to paste into a review or a ticket.

Frequently Asked Questions

Is this SQL formatter free?

Yes - completely free, with no sign-up, no size limit and no daily cap.

Which SQL dialects does it support?

The formatter works on clause structure, not dialect rules, so standard SQL from MySQL, PostgreSQL, SQL Server, SQLite and others all format the same way. It beautifies layout only - it does not validate that your query would run.

Does it re-indent subqueries?

No - parenthesised subqueries stay on the line where they appear. Deep subquery indentation is where formatters most often guess wrong, so this tool sticks to clause-level layout and says so honestly.

Are my string literals safe?

Yes. Single-quoted strings (including doubled-quote escapes), double-quoted and back-quoted identifiers pass through byte-for-byte; only keywords outside them are uppercased.

Is my SQL uploaded to a server?

No. Formatting happens 100% in your browser. Your queries - schema names and all - never leave your device.

Related Developer Tools

Embed this tool on your website — free

Add this tool to your own website or blog — it is completely free, needs no sign-up, and always shows the latest version. Copy the code below and paste it into your page where you want the tool to appear. Keeping the small “Powered by Loona Automation” credit line under the embed helps keep this tool free — but you are free to style or remove it; the tool works either way.