Start a project

Tool 53 of 100 · Data

SQL Formatter

Paste a long one-line query and get readable SQL with each clause on its own line, indented joins and subqueries, and keywords in the case you like.

SQL Formatter at a glanceIllustration: 1, Messy SQL; 2, processed in your browser; 3, Readable SQL.SQL Formatter</>1Messy SQL3Readable SQL2In yourbrowser
1 Messy SQL 2 processed on your device 3 Readable SQL

SQL Formatter

Your SQL

Formatted

SQL

01

What it does

Pretty-prints or minifies SQL with clauses on new lines, indented conditions and nested subqueries, keeping strings exact.

  • SELECT, INSERT, UPDATE, DELETE, CTEs and DDL
  • Indented joins, conditions and subqueries
  • Strings, quoted names and comments kept exactly
  • Upper, lower or unchanged keywords

02

Private by design

Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

03

What you get

Formatted or minified .sql, with a Copy and a Download button on every result.

  • SQL
  • Formatter
  • PostgreSQL
  • MySQL

Why it matters

Queries copied from logs, ORMs or monitoring tools arrive as one long line. Reading a 40-column join like that is the quickest way to miss a wrong condition.

This formatter tokenises the SQL properly, so strings, quoted identifiers and comments are never changed, then lays it out with each clause on a new line and AND/OR conditions indented under it. Subqueries and CTEs nest, which makes the structure of a complex query obvious.

How it works

  1. InputSQL from a log, an ORM or a colleague
  2. In your browserTokenised with strings and comments kept intact
  3. OutputFormatted or minified SQL with a summary

Where it fits in a designer's workflow

  1. Plan
  2. Design
  3. Build
  4. Test
  5. Launch
Reading and reviewing queries.

By the numbers

The sample query as pasted, formatted and minifiedAs pasted: 2 lines: 722 bytes; Formatted: 49 lines: 832 bytes; Minified: 1 line: 677 bytesAs pasted: 2 lines722 bytesFormatted: 49 lines832 bytesMinified: 1 line677 bytes
Measured with this tool's own formatter on its sample: 2 statements, 5 tables, 2 joins and 2 subqueries. Formatting adds whitespace for people; the database ignores it, so minifying only matters when a query is embedded in code or a URL. Source: PostgreSQL: SELECT.
Show the numbers as a table
VersionBytesLines
As pasted7222
Formatted83249
Minified6771

How to use it

  1. Paste your SQL.
  2. Choose the keyword case and indent.
  3. Read the formatted query.
  4. Copy or download it, or minify it instead.

FAQ

Which dialects work?

The common syntax shared by PostgreSQL, MySQL, SQLite and SQL Server, including backtick, double-quote and bracket identifiers.

Will it change my query?

Only whitespace and, if you choose, keyword case. Strings and names are left exactly as written.

Does it check the SQL is valid?

It checks the brackets and quotes balance, but it doesn't run or validate the query against a database.

Can it format several statements?

Yes. Separate them with semicolons and each is formatted in turn.

Work with me

Want a site that gets these right?

I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

All developer tools · Back to leej.uk