Skip to tools

Formatters

SQL Formatter

Queries copied from ORM logs or written in a hurry tend to become one long line. The SQL Formatter uppercases keywords and moves clauses such as SELECT, FROM, JOIN, WHERE, GROUP BY and ORDER BY onto separate lines so the logic of the query is visible at a glance.

Readable SQL is easier to review, easier to optimise and far easier to explain to a teammate.

How to use the SQL Formatter

  1. 1Use the SQL Formatter right on this page, or open the full workspace for history, sharing and every other tool.
  2. 2Paste your input, upload a file, or drag and drop a file onto the input box (up to 25 MB).
  3. 3The result appears in the output panel automatically and updates when you change the input or an option.
  4. 4Use Copy Output or Download to save the result. Nothing is uploaded to a server.

Example

A single-line join query is broken into clauses with keywords in uppercase.

Input
select id,name from users where active=1 order by name
Output
SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
ORDER BY
  name

When to use it

  • Reading a query captured from application logs or an ORM debug output
  • Preparing SQL for a code review or a database migration script
  • Explaining a report query to a non-technical colleague

Tips and common mistakes

  • Long column lists are split one per line, which makes spotting a missing comma easy.
  • Format before saving queries in documentation so they stay consistent.
  • String literals are left untouched, so values inside quotes keep their case.

Frequently asked questions

Which SQL dialects are supported?

Standard SQL keywords used by MySQL, PostgreSQL, SQL Server, SQLite and Oracle are recognised.

Does it validate my query?

It formats the text but does not connect to a database, so logical errors are not detected.

TutorialWhy you should format your SQL (and how)

Related tools

Ready to try it?

Free, no sign-up, and your data never leaves your browser.