Skip to content
DoItJag

SQL Formatter

Turn a long one-line query into readable SQL, with each clause on its own line and keywords in the case you prefer.

or drop a file here · .sql, .txt · up to 20 MB

Options

About the SQL Formatter

Queries copied from application logs, ORM debug output or a colleague’s chat message usually arrive as one long line. This formatter puts each clause on its own line, indents the columns and conditions beneath it, and writes keywords in the case you choose.

It uses the open-source sql-formatter library. Your query is read and re-printed in the browser; it is never run against any database.

When to use it

  • A slow query from a log needs to be understood before you tune it.
  • You are pasting SQL into a ticket, a code review or documentation.

Worked example

The Try an example button fills in a single-line report query that joins orders, customers and order items, filters by date and country, groups, and keeps the ten biggest totals. Leave Standard SQL, 2 spaces and UPPER CASE selected, then press Format SQL.

SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT each start a new line. The three selected columns are listed one per line, each JOIN with its ON condition sits under FROM, and the second WHERE condition starts with AND on its own line. The date and country strings are untouched, and the function name sum keeps its original case because only keywords are changed.

Choosing the dialect

Databases disagree on quoting and syntax. MySQL uses backticks around names, SQL Server uses square brackets, and PostgreSQL has dollar-quoted function bodies and the :: cast operator. Picking the matching dialect lets the formatter read these correctly. If you see an error on a query you know runs, the dialect is the first thing to change.

Good to know

  • The formatter does not check that tables or columns exist, or that the query is valid; it only needs to tokenise it.
  • Comments are kept.
  • Several statements separated by semicolons are formatted one after another with a blank line between them.
  • To pack a query back onto one line, use the SQL minifier.

How to use SQL Formatter

  1. Paste SQL or open a .sql file.
  2. Choose the SQL dialect, indentation and keyword case.
  3. Select Format SQL, check the result, then copy or download it.

Privacy: how it works

Everything happens in your browser. Your text is not sent to any server.

Frequently asked questions

Is my query run against a database?

No. The query is only read and re-printed in your browser. It is never run and never sent anywhere.

Why should I choose a dialect?

Databases differ in quoting, operators and keywords. Choosing the right one helps the formatter read things such as backtick names in MySQL or $$ blocks in PostgreSQL.

Does it check that my SQL is correct?

No. It formats the query but does not check table names or full grammar. It reports text it cannot read, such as an unclosed quote.