Skip to content
TabBench

SQL Formatter

Beautify, indent, format, and minify SQL queries with customizable casing and spacing.

Runs in your browser. Nothing you add is uploaded.

What the SQL Formatter does

Paste a SQL query that arrived on one line, from an ORM log, a slow-query report or an error message, and this formatter puts each clause (SELECT, FROM, each JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT and so on) on its own line, indents the lines in between, and sets keywords to upper case, lower case or leaves them as typed. String literals and comments are never altered, so a value like 'it''s -- not a comment' comes through intact. Minify does the reverse, collapsing the query to a single line without comments.

How to format SQL

  1. Paste your query, or load a preset: a JOIN with GROUP BY, an INSERT, a CTE with window functions, or an UPDATE with a subquery.
  2. Choose keyword casing: UPPERCASE, lowercase or preserve.
  3. Choose indentation: 2 spaces, 4 spaces or a tab.
  4. Turn on Minify for a one-line version without comments.
  5. Copy the result, or download it as query.sql (query.min.sql when minified).

The SQL Formatter runs entirely in your browser — nothing you enter is uploaded, stored, or logged.

When to use it

Reading ORM-generated queries

Hibernate, Django, Prisma and ActiveRecord log queries as one long line full of aliased columns. Breaking it at each clause shows at a glance which tables are joined and what the WHERE conditions are, which is often enough to spot the unexpected JOIN or missing LIMIT behind a slow request.

Consistent queries in code review

Migrations and report queries written by different people drift into different styles. Running them through the same casing and indentation before committing means the diff shows real changes rather than whitespace.

One-line queries for scripts

Some places need a query on a single line: a psql -c argument, a cron entry, a JSON config value. Minify removes line breaks and comments and keeps every string literal exactly as written.

Good to know

  • Formatting never changes what a query does; databases ignore whitespace and keyword case. String contents and quoted identifiers are left alone.
  • A line comment (-- note) keeps its own line, so nothing that followed it is accidentally commented out.
  • The formatter is deliberately simple: it breaks lines at clauses, but does not put each selected column on its own line or indent nested subqueries by depth.
  • It is dialect-neutral text processing, so PostgreSQL, MySQL, SQLite and SQL Server syntax pass through, but it does not check that the query is valid.
  • Minify removes all comments, including optimizer hints written as /*+ … */ in MySQL and Oracle. Format instead of minifying if you need to keep them.

Frequently asked questions

Why should SQL keywords be in uppercase?

Capitalizing keywords like SELECT, FROM, and WHERE makes SQL code much easier to distinguish from table and column identifiers, improving readability in code reviews and debugging sessions.

Does this tool work offline?

Yes. The query formatting logic runs entirely within your browser tab, ensuring sensitive database table names and queries never leave your machine.

Does formatting alter the query execution plan?

No. Query planners ignore whitespace, line breaks and keyword case, so the formatted query runs exactly like the original.

Does it check my SQL for errors?

No. It does not parse SQL grammar, so a query with a typo is formatted like any other. Run it against your database, or use EXPLAIN, to check it.

Page last updated . Found a wrong result or a mistake on this page? Let us know.