SQL Formatter

Runs entirely in your browser

Beautify SQL queries directly in your browser. This only rewrites text — it never executes your SQL.

Advertisement

Advertisement

What is SQL Formatter?

SQL Formatter rewrites a SQL query onto multiple readable lines — one clause per line, comma-separated columns indented underneath SELECT, and keywords uppercased — without changing what the query does. It's purely a text transformation and never connects to a database.

How to use SQL Formatter

  1. Paste your SQL query into the Input box.
  2. Click Format.
  3. Copy the readable result from the Output box.

Features

  • Supports SELECT, INSERT, UPDATE, DELETE, JOINs, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT and CASE.
  • Uppercases SQL keywords for readability.
  • Preserves string literals and comments exactly.
  • Never executes or connects to a database — text in, text out.
  • 100% client-side — your SQL never leaves your browser.

Example

This one-line query:

select id, name, email from users where status = 'active' and created_at > '2024-01-01' order by created_at desc limit 20;

becomes:

SELECT id,
   name,
   email
FROM users
WHERE status = 'active'
  AND created_at > '2024-01-01'
ORDER BY created_at DESC
LIMIT 20;

Tips for using SQL Formatter

  • Single-quoted string values are tracked separately from bare words, so a value like 'select' or 'from' inside quotes is never mistaken for a keyword and left exactly as typed — including its original case.
  • Function calls such as COUNT(*), SUM(price) or MAX(id) are recognized specifically, so they get no space before their parenthesis, while clause keywords like VALUES (...) or IN (...) keep the conventional space.
  • Continuation lines for a multi-column SELECT list are indented two spaces past the SELECT keyword's line, as shown in the Example above.
  • This is a tokenizer, not a full SQL grammar — it recognizes the common ANSI clauses listed in the FAQ below, but an unusual vendor-specific construct outside that list may not get its own line the way you'd expect.

Is SQL Formatter safe?

Yes. The same tokenizer described in the Tips above — the one that tracks quoted strings and identifiers separately from keywords — runs locally in your browser, so your query is rewritten and displayed without ever connecting to a database, executing anything, or being sent to our servers.

Frequently Asked Questions

Does this execute my SQL?

No. This tool only rewrites the text of your query for readability. It never connects to a database or executes anything.

Which SQL dialects does this support?

It formats common ANSI SQL syntax — SELECT, INSERT, UPDATE, DELETE, JOINs, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT and CASE — used across MySQL, PostgreSQL, SQL Server and SQLite. It's a text-based formatter, not a full SQL parser, so highly unusual or vendor-specific syntax may not format perfectly.

Will formatting change what my query does?

No. Only whitespace, line breaks and keyword casing change — every identifier, literal and operator is preserved exactly.

Related tools