Skip to content
Runs local · no upload

Format SQL Queries Instantly

Paste any SQL query — minified, messy, or single-line — and get properly indented, keyword-capitalized output with consistent clause alignment in seconds.

Ausgabe
Eingabe leer — oben einfügen, um die formatierte Ausgabe zu sehen.

How It Works

  1. 01

    Paste text or code

    Paste your content into the input field or type directly.

  2. 02

    Instant processing

    The tool processes your content immediately and shows the result.

  3. 03

    Copy result

    Copy the result to your clipboard with one click.

Privacy

All calculations run directly in your browser. No data is sent to any server.

Unformatted SQL is a common frustration: code dumped from an ORM, a minified query from a log file, or a co-worker's 800-character single-line SELECT. This formatter parses your SQL and outputs it with proper indentation, capitalized keywords, and aligned clauses — making it readable in seconds without any manual cleanup.

01 — How to Use

How do you use this tool?

  1. Paste your SQL query into the input field — any dialect, any length.
  2. Select your target SQL dialect: MySQL, PostgreSQL, SQL Server, or SQLite.
  3. Click Format (or let it format automatically as you type).
  4. Copy the formatted output or download it as a .sql file.
  5. To minify instead, use the Minify toggle to produce a single-line version for production use.

What This Tool Does

The SQL Formatter takes raw, unformatted, or minified SQL queries and outputs clean, consistently styled code. It handles all common SQL constructs — SELECT with multiple JOINs, CTEs, subqueries, INSERT/UPDATE/DELETE, DDL statements, and stored procedures — and respects dialect differences between MySQL, PostgreSQL, SQL Server, and SQLite.

How It Works

The formatter tokenizes your SQL input into a stream of keywords, identifiers, operators, and literals, then applies indentation and capitalization rules based on the selected dialect. No query is executed — the tool only parses and reformats the text structure.

Default formatting style:

RuleBehavior
KeywordsUppercase (SELECT, FROM, WHERE, JOIN)
IdentifiersPreserved as-is
Indentation2 spaces per level
Clause alignmentEach major clause on its own line
CommasTrailing (end of line)
SubqueriesIndented one additional level

Before:

select u.id,u.name,o.total from users u left join orders o on u.id=o.user_id where o.total>100 order by o.total desc

After (PostgreSQL):

SELECT
  u.id,
  u.name,
  o.total
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE o.total > 100
ORDER BY o.total DESC

What Are Common Use Cases?

Reading ORM-generated queries — ORMs like Django ORM, SQLAlchemy, ActiveRecord, and Hibernate generate SQL that is functional but unreadable. Enable SQL logging, paste the output into the formatter, and understand exactly what query your application is running — useful for performance debugging and N+1 query detection.

Database log analysis — Slow query logs from MySQL, PostgreSQL, and AWS RDS contain minified queries. Format them to identify missing indexes, full table scans, or cartesian joins before presenting findings to a team.

Code review of database migrations — Rails migrations, Flyway scripts, and Liquibase changesets often include hand-written DDL. Format before review to catch structural issues (missing indexes, wrong column types) that are hard to spot in compressed form.

Interview preparation and SQL exercises — Developers practicing on LeetCode, HackerRank, or StrataScratch often write queries in a hurry. Format before submission to present clean, professional code.

Documentation and runbooks — Operational runbooks and internal wikis include SQL snippets for maintenance tasks. Formatted SQL is easier to copy, modify, and execute safely during an incident.

Sharing queries in Slack or GitHub — Formatted SQL in a code block is immediately readable without asking colleagues to mentally parse a compressed string. Paste formatted output directly into PR comments or Slack messages.

Frequently Asked Questions

Should I use leading or trailing commas in SQL? Both are valid. Trailing commas (col1,\n col2,) are the SQL standard default and what most teams use. Leading commas (,col1\n,col2) make it easier to comment out individual columns without touching the previous line. This tool defaults to trailing commas but supports both styles in settings.

Can the formatter detect and report SQL syntax errors? Basic syntax errors (unmatched parentheses, unclosed strings) are flagged during tokenization. The formatter does not execute queries, so semantic errors (referencing columns that don’t exist) are not caught. For full query validation, run against a live database or use a linter like sqlfluff.

How do I format SQL in VS Code without a plugin? VS Code has no built-in SQL formatter, but extensions like “SQL Formatter” (based on the same sql-formatter npm library) provide integrated formatting. For one-off formatting without installing extensions, this browser tool is the fastest path.

Last updated:

You might also like