DevToolCase
Sign in Sign in

Format SQL

Indent SQL queries for MySQL, PostgreSQL, SQL Server, Oracle, SQLite, BigQuery…, keywords in upper or lower case; minify them too.

Share this result

Encrypted in your browser. The key stays in the link, after “#”: only the people you give it to can read it, not even DevToolCase.

The link works for

Sign in for longer links or links without expiry, and to find them in your account.

Runs entirely in your browser: nothing you type is sent or stored.

Why format SQL?

  • Read a query copied from the logs of an ORM (Hibernate, Doctrine, Entity Framework, Prisma…), which writes it on a single line.
  • Review code: when every team member formats the same way, a diff only shows what really changed.
  • Debug a long query: with one clause per line and the subqueries indented, a missing join condition or a misplaced parenthesis shows at a glance.

Formatting conventions

There is no official standard, but most teams agree on a few rules, which this formatter applies:

  • Each main clause on its own line: SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY.
  • The columns and conditions under it, indented, one per line.
  • Keywords in upper case, names as they are: SELECT name FROM users tells the language from your data. Lower case is fine too, as long as it is consistent.
  • Subqueries indented one more level, inside their parentheses.

Why choose the dialect?

Every database extends SQL its own way, and the formatter must know which to read the query correctly:

DialectIts own syntax
MySQL, MariaDBNames in backquotes, # comments, LIMIT.
PostgreSQL:: casts, $$…$$ strings, ILIKE, RETURNING.
SQL Server (T-SQL)Names in [brackets], TOP, @variables.
Oracle PL/SQLBEGIN … END blocks, :bind variables, CONNECT BY.
BigQueryNames in backquotes, with dots (project.dataset.table), STRUCT, ARRAY.

With “Standard SQL”, a quote or an operator of another dialect may be reported as an error: choose the dialect of your database.

Is my query sent anywhere?

No. The query is formatted in your browser: table names, values and customer data stay on your device. To put it back on a single line, minify it.

Add this browser’s favorites to your account?

This browser has 0 favorites that your account does not have:

Either way, this browser keeps its favorites: you find them again after signing out.