Skip to content
T
Tools.Town
Free Online Tools for Everyone
SELECT …

SQL Formatter

100% Free

Format, beautify, and re-indent messy SQL queries into clean, readable code — keywords cased your way, clauses on their own lines, runs entirely in your browser.

Keyword-Aware
Instant Format
Upper / lower
100% Client-Side
Indent
Formatted SQL
Type or paste SQL to see it formatted…
Indent
Formatted SQL
Type or paste SQL to see it formatted…

Embed This Tool

Easy to Embed

Add SQL Formatter to your website or blog in seconds.

  • Responsive design
  • Lightweight & fast
  • No backend required
  • Always up-to-date
<iframe
  src="https://tools.town/embed/sql-formatter/"
  width="100%"
  height="600"
  style="border:none; border-radius:12px;"
  loading="lazy"
  title="SQL Formatter">
</iframe>

Share This Tool

Share Instantly

Share SQL Formatter with anyone — no login required.

  • Shareable link
  • No login required
  • Works on any device
  • No account needed

Share via

Advertisement

How to Use

  1. 1 Paste or type your SQL query into the input panel
  2. 2 Toggle 'Uppercase keywords' on or off to match your house style
  3. 3 Pick your indentation: 2 spaces, 4 spaces, or a tab
  4. 4 Read the beautified query in the output panel on the right
  5. 5 Click Copy and paste the clean SQL back into your editor or migration

Features

  • Tokenises SQL into keywords, identifiers, strings, numbers, and comments before re-indenting — so it never breaks your query
  • Puts every major clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, LIMIT, UNION) on its own line
  • Indents SELECT columns, JOIN ON conditions, and AND/OR predicates underneath their clause
  • Casts keywords to upper or lower case on demand without touching identifiers or string contents
  • Preserves string literals and -- / block comments exactly as you wrote them
  • 100% client-side — your SQL is never uploaded; saved profiles, batch, and API come with Pro

Why it Matters

A query that runs fine can still be unreadable — everything crammed on one line, inconsistent casing, no indentation. That makes code review slow, diffs noisy, and bugs easy to hide. A consistent format puts each clause where your eye expects it, so JOINs, filters, and grouping are obvious at a glance. This formatter tokenises the SQL first, so it re-indents and re-cases keywords without ever altering what's inside your strings or comments — the query you paste is the query you get back, just legible.

★★★★★

Use Cases

Code Review

Format queries before opening a PR so reviewers read clauses, not a wall of text

Migrations & Scripts

Clean up generated or hand-written DDL/DML so the next person can follow it

Docs & Tickets

Paste a readable query into a runbook, wiki, or bug report

House Style

Standardise uppercase keywords and indentation across a whole team

What this tool does

The SQL Formatter turns a cramped, one-line, inconsistently-cased SQL query into clean, readable code. Paste your query, choose whether keywords should be uppercase or lowercase, pick your indentation, and copy the beautified result straight back into your editor, migration, or pull request.

How it works

Rather than blindly find-and-replacing text, this formatter tokenises your SQL first — it splits the input into keywords, identifiers, string literals, numbers, operators, punctuation, and comments. Because it understands those token types, it can put every major clause on its own line, indent SELECT columns and JOIN ... ON conditions, and re-case keywords without ever touching what’s inside your strings or comments. A literal like 'select from where' comes back exactly as you typed it.

Free vs Pro

The formatter here is free forever and runs entirely in your browser — no account, nothing stored. For teams that want one house style everywhere, SQL Formatter Pro is planned to add saved formatting profiles, batch-formatting whole folders of .sql files, a CLI/API for CI pipelines, and dialect-aware rules. Only the free single-query formatter ships today.

Privacy

Everything runs locally in your browser. The queries you format are never uploaded, logged, or stored.

Frequently Asked Questions

What does a SQL formatter actually do?
It re-indents and re-cases your SQL so it's easy to read, without changing what the query does. This tool tokenises the SQL into keywords, identifiers, strings, numbers, and comments, then puts each major clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, etc.) on its own line and indents the columns and conditions underneath.
Will it change anything inside my string literals or comments?
No. String literals (like 'select from where') and both -- line comments and block comments are preserved exactly as you wrote them. The formatter only re-cases real keywords and adjusts whitespace between tokens, so the meaning of your query never changes.
Can I keep my keywords lowercase?
Yes. Uppercase keywords is the default because it's the most common convention, but you can switch it off and the tool will lowercase SELECT, FROM, WHERE, JOIN and every other keyword while leaving your table and column names untouched.
Is the SQL Formatter free, and does it store my queries?
The formatter is completely free and runs entirely in your browser — nothing is uploaded or saved. Saved formatting profiles, batch-formatting many files, a CLI/API for CI, and dialect-aware rules are planned SQL Formatter Pro features; the core single-query formatter always stays free.
Which SQL dialects does it support?
The free tool uses a dialect-agnostic keyword set that covers the common ANSI SQL used by Postgres, MySQL, SQLite, SQL Server, and most engines. Dialect-specific formatting rules for Postgres, MySQL, T-SQL, and BigQuery are a planned Pro feature.

Related Tools You Might Like

Browse more free tools