SQL Formatter

Uppercase SQL keywords and put major clauses on their own lines for readable queries.

SQL Formatter

Uppercase SQL keywords and put major clauses on their own lines for readable queries.

Paste a flat SELECT query to get keywords uppercased and each clause — SELECT, FROM, WHERE, JOIN, ORDER BY, LIMIT — placed on its own line with AND/OR conditions indented. Quoted string literals are preserved verbatim. This is a best-effort formatter for everyday queries, not a full SQL parser.

How to use this calculator

  1. Paste your SQL query into the input box.
  2. Choose Format for uppercased keywords with one clause per line, or Minify for a single line.
  3. Click Format.
  4. Scan the output — verify JOIN conditions and string literals look right.
  5. Copy the readable query into your editor or docs.

The formula

The query is tokenized with string literals preserved; recognized keywords are uppercased and multi-word keywords merged; then tokens are re-emitted with SELECT/FROM/WHERE/JOIN/ORDER BY/LIMIT starting new lines and AND/OR/ON indented one level.

Worked example

Formatting select id, name from users where age > 18 and active = 1 order by name limit 10 produces six lines: SELECT id, name, then FROM, WHERE, an indented AND condition, ORDER BY name, and LIMIT 10 — with every keyword uppercased.

Frequently Asked Questions

What kind of queries does it handle best?

Single-level SELECT statements with WHERE filters, JOINs, GROUP BY, ORDER BY, and LIMIT clauses — the bread-and-butter queries you copy out of logs or an ORM. It uppercases keywords, merges multi-word keywords like LEFT JOIN and ORDER BY, and indents AND/OR conditions.

What are its limits?

It is explicitly a best-effort formatter, not a full parser. Deeply nested subqueries, CTEs (WITH clauses), window functions, and vendor-specific procedural SQL get only basic treatment — clauses are still uppercased, but indentation of exotic constructs may need manual touch-up.

Will it change my string literals?

No. Single-quoted, double-quoted, and backtick-quoted literals are detected and passed through exactly as written, including escaped quotes like 'o''brien'. Only bare keywords outside of strings are uppercased.

What does minify mode do?

It collapses the query to a single line with normalized single spaces and uppercased keywords — handy for embedding a query in code or a log line. Unlike the pretty mode, it keeps everything on one line with no indentation.

Is my query sent anywhere?

No. Formatting runs entirely in your browser, so queries containing table names, customer data, or proprietary logic never leave the page.