SQL Formatter

Format SQL neatly with indentation and highlighted keywords, making your code easier to read, review, and maintain over time. GDPR-compliant.

The result will appear here …

How to use this tool (video)

This video is hosted on YouTube. When you play it, data may be sent to Google.

SQL Formatter: Make Your Queries Readable

Compact SQL queries are quick to write but hard to read. When a SELECT nests several JOINs, WHERE conditions and ORDER BY clauses, keeping the overview quickly becomes guesswork. This SQL formatter indents your query automatically, puts line breaks at the important keywords and makes the code readable in seconds, all in your browser without sending the query to a server.

How the formatter works

The tool splits your query into small tokens and reassembles them. Keywords such as SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, LIMIT, SET, VALUES, ON and logical connectors like AND/OR each start their own line. Nested parentheses and subqueries are recognized and indented. Importantly, string literals, -- line comments and /* block comments */ stay untouched, because they are treated as separate tokens and never torn apart.

Example input:

SELECT id,name,email FROM users WHERE age>18 AND city='Berlin' ORDER BY name LIMIT 10;

Example output (structural):

SELECT id, name, email
FROM users
WHERE age > 18
AND city = 'Berlin'
ORDER BY name
LIMIT 10;

The casing of your keywords (upper or lower) is preserved; the formatter only changes line breaks and indentation.

Limits: it formats, it does not validate

It is worth knowing what the tool does not do:

  • No validation: The formatter does not check whether your SQL is syntactically correct. It does not catch wrong column names, missing commas or logic errors; it only beautifies the presentation.
  • No execution: No query is run against a database. There are no results, no errors and no database access.
  • No rewriting: The content and order of your query stay unchanged. If your SQL is wrong, it stays equally wrong after formatting.
  • Not a full parser: Exotic dialect edge cases may be treated differently than by a full database parser.

Treat the formatter as a pure readability aid. Your database or a dedicated SQL validator does the actual syntax checking.

Which SQL dialects are covered

The formatter works on a keyword basis and handles the most common dialects such as MySQL, MariaDB, PostgreSQL, SQLite and SQL Server for typical SELECT, INSERT, UPDATE and DELETE queries. Even long queries with many JOINs and subqueries are processed; the longer the query, the bigger the readability gain from indentation.

How are subqueries indented?

Parenthesized subqueries are recognized as separate blocks by the formatter and indented one level deeper. This keeps the nesting of SELECT clauses inside WHERE or FROM clearly visible, and you see at a glance which parts of the query belong together. With several JOINs too, every JOIN moves onto its own line, which massively improves the overview especially in complex data models.

When formatting pays off

You save the most time when you have to take over and understand foreign or old queries, whether from logs, from an ORM or from an earlier database migration. Sharing SQL in code reviews or documentation also becomes much more readable through consistent formatting. What remains important: use the tool as a reading aid; you are responsible for syntax and logic. After formatting, the query should be exactly the same in content as before.

A typical use looks like this: you copy a compact query from an older migration, paste it here and get a cleanly indented version you can take into your repository or documentation. Since formatting happens locally, even queries with business-critical data stay on your machine. For several statements you format them one by one and reassemble the results. That keeps every query readable without any external data processing.

Frequently asked questions

Is my SQL query sent to a server?

No. Formatting runs entirely in your browser. Your query is not transmitted to our server or stored.

Which SQL dialects are supported?

The formatter works on a keyword basis and handles the most common dialects such as MySQL, MariaDB, PostgreSQL, SQLite and SQL Server for typical SELECT, INSERT, UPDATE and DELETE queries.

Can the formatter handle very long queries?

Yes. Even extensive queries with many JOINs and subqueries are processed. The longer the query, the greater the readability gain from indentation.

How does indentation work for parentheses and subqueries?

Indentation increases at every opening parenthesis and decreases at every closing one. Nested subqueries therefore stay visually separated.

Does the formatter check whether my SQL is correct?

No. The formatter neither validates syntax nor logic and executes nothing. It only improves the presentation and readability of your query.

Are my data stored?

No. Formatting runs completely in your browser. Your query is not transmitted to our server and is not stored.