Developer Tools

SQL Formatter

Format and beautify SQL queries.

How to Use SQL Formatter

1

Paste your query into the box, including a stored procedure body or a WITH clause if you have one.

2

Pick a dialect hint and a keyword casing style, either lower case or upper case.

3

Click the "Process" button to rebuild the query with one clause per line and aligned indentation.

4

Copy the formatted SQL or download it for a migration, doc block, or code review comment.

Features

Splits SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, and ORDER BY onto separate lines
Uppercases or lowercases reserved keywords without touching identifiers or strings
Indents nested subqueries and common table expressions by depth
Keeps string literals, quoted identifiers, and comments exactly as written
Cleans up generated queries from logs before you post them in a bug report
Runs in the browser so queries containing real data never leave your machine

Frequently Asked Questions

No. The tool only alters whitespace and keyword casing, both of which are insignificant to the SQL parser. It never reorders clauses, rewrites joins, or changes an operator, so the query returns exactly the same rows and the same execution plan.
Only reserved keywords such as SELECT and ORDER BY are cased. Identifiers, including quoted and mixed-case table names, are left exactly as they appear in your source, so a schema with case-sensitive names is not broken.
Yes. WITH clauses, window functions with OVER, and chained JOINs are all handled and indented by nesting depth. The formatting is structural, so unusual clause combinations still come out readable.
It is free, needs no sign-up, and there is no practical length limit. Processing happens in your browser, so a query containing customer data is never uploaded or stored.

About SQL Formatter

Long queries in a log file or a saved report are close to unreadable. Six JOINs with the same three-line WHERE clause repeated in each subquery, all lowercase, all on one line. The SQL Formatter rebuilds the statement so each clause starts on its own line, with indentation that reflects how deeply nested you are.

SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT are broken out one per line, subqueries are indented inside their parentheses, and common table expressions are offset so the main query at the bottom is easy to find. Reserved keywords can be uppercased or lowercased to match your team convention.

What it does not touch matters just as much. String literals, quoted identifiers, and comments come through byte for byte, so a query containing a regex in a string or an escaped quote is not corrupted. No identifiers are renamed and no clause is reordered, so you can run the formatted query against your database and get the same plan and the same rows.

When to Use This Tool

  • Reading a query copied out of application logs before opening an issue
  • Cleaning up a generated report query before adding it to a migration
  • Formatting SQL for documentation, runbooks, or a blog post
  • Reviewing a complex query in a pull request that changed only one condition
  • Standardising ad-hoc queries written during an incident