SQL Formatter Online — Beautify Queries from Any Dialect

SQL Formatter Tool

SQL

About the SQL Formatter Tool

Overview

ORM-generated queries and anything pulled from a slow-query log tend to come out as a dense single line, which makes catching a missing JOIN condition or a redundant subquery much harder than it should be. This formatter re-indents JOIN, WHERE, GROUP BY, and similar clauses onto their own lines so the query's structure is visible at a glance, which speeds up both code review and writing documentation.

How to Use

  1. 1Paste the query — copy it straight from your ORM's debug log if that's easier.
  2. 2Pick 2 or 4 spaces under Indentation to match your team's style guide.
  3. 3Under Mode, choose Standard Format for normal readability, Right-aligned/Tabular if you want keywords lined up in a column, or Minify to flatten everything to one line.
  4. 4Set Keywords and Identifiers independently to Uppercase, Lowercase, or Preserve, depending on your house style for SQL casing.
  5. 5Hit Format and the cleaned-up query appears on the right, ready to copy into a review comment or doc.

Specifications & Glossary

  • Mode: Formatting method selection
    • Standard Format: The familiar style most style guides recommend — each clause on its own line, indented under the keyword it belongs to.
    • Right-aligned/Tabular: Right-justifies keywords so SELECT, FROM, WHERE, and friends line up in a vertical column — a layout some teams (and some legacy style guides) prefer over Standard Format.
    • Minify: Removes line breaks and extra spaces, compressing to a single line.
  • Keywords: SQL keyword upper/lower conversion
    • Uppercase: Converts all SQL keywords such as SELECT and FROM to uppercase.
    • Lowercase: Converts all SQL keywords to lowercase.
    • Preserve: Preserves the original casing of the input.
  • Identifiers: Controls casing for table and column names independently from keywords — set it to Uppercase, Lowercase, or Preserve to match your schema's naming convention.
  • Indentation: Sets the number of spaces used for indentation in the output SQL (e.g., 2 spaces, 4 spaces).

Use Cases

  • Cleaning up a query before opening a pull request, so reviewers spend their time on logic instead of deciphering formatting.
  • Untangling a query an ORM (Sequelize, Prisma, ActiveRecord, etc.) generated, especially once it includes several joined tables.
  • Producing a clean SQL snippet to drop into a runbook, wiki page, or onboarding doc.
  • Sorting out SQL where an ORM has interleaved bind-parameter placeholders or auto-generated comments with the actual clauses — a common source of "why won't this query format right" confusion that a plain text editor can't fix.