Skip to content
SmaftyTools

SQL Formatter

Format SQL queries with uppercase keywords and clean clause indentation. Free online SQL beautifier — runs in your browser.

About SQL Formatter

The SQL Formatter is a free sql formatter that turns cramped, single-line queries into readable SQL: keywords are uppercased and major clauses — SELECT, FROM, WHERE, JOINs, GROUP BY, ORDER BY — each start on their own line with sensible indentation. It's the fastest way to pretty print sql you've copied from a log file, an ORM's generated output, or a colleague's Slack message. It also helps when learning SQL — seeing a query broken into its component clauses on separate lines makes the logical structure (what's being selected, from where, filtered by what) far easier to follow than a dense single line.

Long queries — the kind an ORM like Prisma, Sequelize or Hibernate generates, or a query pulled from slow-query logs — are nearly impossible to review as one continuous line. Running them through the sql beautifier turns that wall of text into a query you can actually scan for the right JOIN condition, spot a missing WHERE clause, or diff against a previous version in a code review. It's equally handy for cleaning up your own SQL before committing it to a migration file or a saved query. It's also useful before a code review: a formatted query is easier for a reviewer to scan for a missing index-friendly WHERE clause, an accidental cross join, or a SELECT * that should really list specific columns.

The formatter recognizes standard SQL keywords shared across PostgreSQL, MySQL, SQL Server, SQLite and most other dialects, uppercasing them consistently while leaving identifiers, table names and string literals exactly as written — so the query means precisely the same thing before and after. Multiple statements separated by semicolons are each formatted in turn, and comments in the original query — whether inline -- comments or /* block comments */ — are preserved rather than stripped, since silently removing them could delete context a teammate left for a reason.

Formatting runs entirely in your browser, so production queries, table names and schema details containing business logic never leave your machine — useful when the query itself is sensitive.

How to Use the SQL Formatter

  1. Paste your SQL query into the input pane.
  2. The formatted query appears instantly with uppercase keywords and one clause per line.
  3. Copy the result back into your code or editor.

Features

  • Uppercases SQL keywords automatically
  • New line per major clause, indented JOINs and conditions
  • Preserves string literals exactly as written
  • Handles multiple statements separated by semicolons

Examples

Formatting a query copied from application logs

Input

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

Output

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

Formatting a query with a JOIN

Input

select o.id, u.name from orders o join users u on o.user_id = u.id where o.status = 'paid';

Output

SELECT
  o.id,
  u.name
FROM
  orders o
JOIN
  users u ON o.user_id = u.id
WHERE
  o.status = 'paid';

Frequently Asked Questions

Which SQL dialects are supported?

The formatter works on standard SQL keywords shared by PostgreSQL, MySQL, SQL Server, SQLite and most other dialects. Dialect-specific syntax passes through unchanged.

Will formatting change what my query does?

No. Only whitespace and keyword casing change; identifiers and string literals are preserved exactly, so the query executes identically.

Can I format multiple SQL statements at once?

Yes — paste several statements separated by semicolons and each one is formatted in turn, in the order it appears, so you can clean up an entire migration file in one pass.

Is the SQL Formatter free?

Yes, the SQL Formatter is completely free with no usage limits. No signup, no account and no installation required.

Is my data safe?

Yes. All processing happens locally in your browser using JavaScript — nothing you type is uploaded or stored on our servers.