sql formattersql beautifiersql queryformat sql

How to Format an Unreadable SQL Query in Seconds

How to format a SQL query in your browser for MySQL, PostgreSQL, SQLite, SQL Server or BigQuery, and why the dialect matters.

August 22, 2026·4 min read

To read a query written on a single line, paste it into the SQL formatter. It's what you need when you copy a query generated by an ORM or inherit a 15-line JOIN written all on one line: the tool puts each clause on its own line, indents by two spaces and uppercases the keywords.

Why a SQL query's formatting matters so much

SQL has no formatting requirements: a query works the same written on a single line as it does perfectly indented across twenty. But the difference for someone who has to read and debug that query is huge. A SELECT with several JOINs, subqueries and nested WHERE conditions is much easier to follow when every clause has its own line and the indentation reflects the query's logical structure.

How to format a SQL query

  1. Paste the SQL query you want to format.
  2. Choose the dialect: standard SQL (the default), MySQL, PostgreSQL, SQLite, SQL Server or BigQuery.
  3. The tool reorganizes the query with one clause per line, two-space indentation and uppercase keywords.
  4. Copy the formatted result.

With this single-line input:

select id,name from users where age>18 order by name

the formatter returns:

SELECT
  id,
  name
FROM
  users
WHERE
  age > 18
ORDER BY
  name

Why the dialect matters (not all SQL is identical)

Although the core of SQL is common across database engines, each one has its own particularities: specific functions, different ways of paginating results and its own data types. The formatter uses the keyword list of the dialect you choose to decide what gets uppercased. ILIKE is a PostgreSQL extension: with the same test query, PostgreSQL uppercases it, while with SQL Server the word limit stays lowercase because the formatter doesn't recognize it as a keyword of that dialect.

When formatting SQL makes a real difference

  • Debugging a slow query: with each clause on its own line it's easier to spot which JOIN or subquery may be causing the problem. If the JOIN types aren't clear yet, this guide explains them.
  • Reviewing someone else's code: a query with its structure visible gets reviewed sooner; one crammed onto a single line has to be rebuilt in your head first.
  • Documenting complex queries: readable formatting is what you expect when sharing a query in documentation or in the team chat.
  • Queries generated by ORMs: many are generated on a single line, so formatting them is the first step toward debugging them.

Frequently asked questions

Does formatting change the query's result? No, the logic doesn't change. It only adjusts spaces and line breaks and uppercases keywords. Single-quoted text, comments, and table and column names are kept as they are.

What happens if the query has syntax errors? An unclosed parenthesis or an unclosed string makes the parser reject the query: the tool shows the first line of the error and generates no output. An incomplete query, such as a SELECT that ends in FROM, is still formatted, because the formatter doesn't check that the query is complete.

Does it work with very long or complex queries? Yes. The more clauses and subqueries it has, the more useful the formatting is.

Do I always need to choose the right dialect? It's worth doing if the query uses functions or keywords specific to one engine, because the dialect decides which words are recognized as keywords.

Is my SQL query uploaded to any server? No. Formatting runs in your browser with the sql-formatter library, and the query never leaves your device.


Format any SQL query for free with the SQL formatter, with support for MySQL, PostgreSQL, SQLite, SQL Server and BigQuery.

Try it without code

SQL Formatter

Beautify SQL of several dialects.

Open SQL Formatter

Built by

Miguel Ángel Colorado Marin (MACM)

Full-Stack Developer · Guadalajara, España

I develop web apps, digital tools and full projects — from design to deployment.

Contact me