Skip to content

SQL Formatter & Beautifier

Beautify and indent SQL queries in your browser. Uppercase keywords, break clauses onto new lines, and indent subqueries. Nothing you paste is sent anywhere.

Runs entirely in your browser. Nothing you paste here is sent to us or anyone else โ€” there is no server processing, no logging of input, and no third-party scripts on this page.

A SQL formatter takes a cramped, single-line query and beautifies it: keywords are cased consistently, major clauses like SELECT, FROM, WHERE and JOIN start on their own lines, and subqueries are indented so the structure is obvious. The tool above does this entirely in your browser. Paste SQL on the left, get readable, indented SQL on the right, then copy or download it. It is a formatter, not a validator or a database client, so it never runs your query and nothing you paste is transmitted anywhere.

What does a SQL formatter do?

SQL is often written or generated as one long line, especially inside application code, log files, or ORM output. That is fine for a machine but hard for a person to read or review. A formatter parses the query into tokens, then re-lays them out with predictable rules: one clause per line, consistent indentation, and uniform keyword casing. The result is easier to scan, easier to diff in code review, and easier to debug, without changing the tokens the database will actually receive.

What this tool changes and what it leaves alone

The formatter only touches presentation. It adjusts three things: whitespace (spaces, tabs, and line breaks), indentation depth, and the casing of recognised keywords. Everything else is preserved exactly:

  • Keywords are upper-cased by default. Switch the Keywords selector to lowercase, or to Preserve to leave them untouched.
  • Identifiers such as table and column names keep their original casing, always.
  • Strings and quoted names are treated as single units. A single-quoted string, a double-quoted or backtick or bracketed identifier is never re-cased or split across lines, and doubled-quote escapes like 'it''s' are handled correctly.
  • Comments โ€” both line comments (-- and #) and block comments (/* ... */) โ€” are kept intact.

How it lays out a query

Major clauses each begin on a fresh line at the base indent, joins hang below the tables they attach to, and each ON, AND, and OR condition is indented one level so the logic reads top to bottom. Columns in a SELECT list are placed one per line. Parenthesised subqueries are indented as a block so you can see where they start and end. A worked example:

SELECT
  u.id,
  u.name,
  (
  SELECT
    count(*)
  FROM orders o
  WHERE o.user_id = u.id
) AS order_count
FROM users u
LEFT JOIN profiles p
  ON p.user_id = u.id
WHERE u.status = 'active'
  AND u.created_at > '2024-01-01'
GROUP BY u.id
ORDER BY order_count DESC
LIMIT 20;

Multiple statements separated by semicolons are each formatted and spaced apart with a blank line.

Common use cases

  • Reading a minified query pulled from application logs or an ORM’s debug output.
  • Cleaning up hand-written SQL before committing a migration or a stored view.
  • Making two queries easier to diff by formatting both with the same settings first.
  • Presenting a query in documentation or a code review with consistent, readable indentation.

Formatter, not a validator or an executor

It is worth being explicit: this tool does not check whether your SQL is correct, and it does not run it. There is no database connection of any kind. It will happily format a query with a typo, a missing table, or a logic error, because its only job is layout. If the input has genuinely broken structure โ€” for example unbalanced parentheses โ€” the output may look odd, but the tool still returns your tokens in the original order, so nothing is silently dropped. Always review the formatted result before running it against a real database.

Which dialects work?

Because the formatter works by structure rather than by enforcing one grammar, it is broadly dialect-agnostic. It recognises the common keywords and the quoting styles used across PostgreSQL, MySQL, SQL Server, SQLite, and others โ€” double quotes, backticks, and square brackets for identifiers; single quotes for strings. It does not, however, guarantee that a given construct is valid in your specific database. For unusual vendor-specific syntax the layout is a best effort built on heuristics, not a complete parser.

Is it private?

Yes โ€” your SQL never leaves your browser. The tokenising and re-formatting happen on your device with no server round-trip, no logging, and no third-party analytics on this page. For extra assurance you can load the page and then work offline, or inspect the client-side source. As a general habit, avoid pasting queries that embed live credentials or secrets into any online tool you have not verified.

Frequently asked questions

Is my SQL sent to a server?

No. The formatter runs entirely in your browser. Your query is tokenised and re-laid-out locally on your device, and nothing you paste is uploaded, logged, or stored. You can disconnect from the internet and it still works.

Does this tool run or validate my SQL?

No. It is a formatter, not a database client or a linter. It rearranges whitespace and casing to make the query readable, but it never connects to a database, never executes anything, and does not tell you whether the query is syntactically valid or will return the right result.

Will formatting change what my query does?

It should not. The tool only changes spacing, line breaks, indentation, and keyword casing. It does not add, remove, or reorder tokens, so the SQL that runs is the same SQL you pasted, just laid out differently. Always review the output before running it.

Can I keep my keywords lowercase?

Yes. Use the Keywords selector to choose UPPERCASE, lowercase, or Preserve. Preserve leaves every word exactly as you typed it and only fixes indentation and line breaks. Identifiers, table names, and string values are never re-cased.

Does it handle strings and comments correctly?

Yes. Single-quoted strings (including doubled-quote escapes like 'it''s'), double-quoted, backtick, and bracketed identifiers, line comments (-- and #), and block comments (/* ... */) are treated as single units, so their contents are never re-cased or broken across lines.

Which SQL dialect does it support?

It is dialect-agnostic. Because it formats by structure rather than by validating against one database, it works reasonably for PostgreSQL, MySQL, SQL Server, SQLite, and others. It recognises common keywords and quoting styles from all of them, but it does not enforce any single dialect's rules.

Why did a complex query not format the way I expected?

Very deeply nested queries, vendor-specific syntax, or unusual constructs can lay out imperfectly because the tool uses structural heuristics, not a full SQL grammar. The output is still the same tokens in the same order, so it remains runnable even when the indentation is not exactly to your taste.

Is it safe to paste a production query here?

The query text never leaves your browser, so pasting is private. That said, treat any online tool with healthy caution and avoid pasting queries that themselves embed real credentials or secrets. The formatting logic is client-side so you can inspect it or run the page offline.