3tej home
← Utilities

What is SQL Formatter / Beautifier?

A SQL Formatter / Beautifier reformats your input for readability without changing its meaning. It parses the source, applies consistent indentation, spacing and casing, and returns a clean copy you can paste back into your project. Paste raw SQL to get properly indented, syntax-highlighted queries.

SQL Formatter / Beautifier

Format and indent SQL queries with syntax highlighting. 100% client-side.

Input SQL

Formatted Output

About this tool

The SQL Formatter takes minified or messy SQL queries and outputs properly indented, readable SQL with syntax highlighting. Supports all major SQL keywords. Runs entirely in your browser.

About SQL formatting

A SQL formatter takes a query written on one cramped line, or with inconsistent spacing, and rewrites it with predictable indentation, line breaks, and keyword casing so a human can read it quickly. SQL itself ignores whitespace, so formatting never changes what a query does; it only changes how easy the query is to understand, review, and debug. The reverse operation, minifying, strips the extra whitespace back out for compact storage or embedding in code.

Well-formatted SQL puts each major clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY) on its own line and aligns the parts beneath it. This makes the shape of the query obvious at a glance, so a missing join condition, an extra comma, or a filter on the wrong column jumps out instead of hiding in a wall of text. This tool runs entirely in your browser, so even production schema names stay private.

How it works

The formatter normalises whitespace, then inserts a newline before each major keyword and indents continuation lines. The logic is structural, not dialect-specific, so it works across MySQL, PostgreSQL, SQL Server, SQLite, and Oracle for everyday queries.

Step 1  Collapse all runs of whitespace to a single space
Step 2  Insert a line break before each clause keyword
        (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, ...)
Step 3  Put AND / OR on their own indented lines
Step 4  Indent lines that are not top-level clauses
Step 5  Uppercase recognised keywords and functions

Minify = reverse of Step 1 only: one line, single spaces

Because the rules touch only whitespace and casing, the formatted output and the original return identical results when executed.

Worked example

Consider a one-line query that joins users to their orders and filters the result. Pasted raw it is hard to scan:

SELECT u.id, u.name, COUNT(o.id) FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.status = 'active' GROUP BY u.id ORDER BY u.name;
  1. Each clause moves to its own line: SELECT, FROM, LEFT JOIN, WHERE, GROUP BY, and ORDER BY each start fresh.
  2. The ON condition stays attached to its JOIN line so the relationship is clear.
  3. Keywords are uppercased and the column list sits under SELECT.
Result: The six-clause query becomes a six-line block where the join, the filter, and the grouping are each visible on their own line. The query runs exactly as before, but a reviewer can now verify the LEFT JOIN keeps users with zero orders in one glance.

Keyword formatting reference

How the formatter treats the common keyword groups.

Keyword groupExamplesFormatting
Clause startersSELECT, FROM, WHERE, HAVINGNew line, no indent
Join familyJOIN, LEFT JOIN, INNER JOIN, ONNew line, condition attached
Grouping and orderGROUP BY, ORDER BY, LIMITNew line, no indent
Boolean connectorsAND, ORNew indented line
FunctionsCOUNT, SUM, COALESCE, CASTUppercased inline

Common pitfalls

  • Expecting it to fix broken SQL. The formatter reshapes whitespace; it does not validate syntax. A query with a real error will still error after formatting.
  • Assuming dialect-specific parsing. Vendor-only functions and exotic syntax are left as-is. The tool formats structure, so unusual constructs may not indent perfectly.
  • Pasting multiple statements at once. The formatter is tuned for a single query. Several statements separated by semicolons may not split as cleanly as one query at a time.
  • Losing string contents to casing. Keyword uppercasing applies to SQL keywords, not to your string literals. Text inside quotes keeps its original case.
  • Confusing format with optimise. Formatting changes readability only. It does not rewrite the query for performance or add indexes.
  • Minifying then editing by hand. A minified one-liner is fine for storage but painful to edit. Re-format it before making changes so you can see the structure.

Frequently asked questions

What SQL dialects does the formatter support?

It handles standard SQL keywords common to MySQL, PostgreSQL, SQL Server, SQLite, and Oracle, including SELECT, FROM, WHERE, JOIN variants, GROUP BY, ORDER BY, HAVING, INSERT, UPDATE, DELETE, and CREATE TABLE. It formats and indents the structure rather than parsing dialect-specific functions, so it works across engines for the vast majority of everyday queries.

Does formatting change what my query does?

No. Formatting only changes whitespace, line breaks, and keyword casing, which SQL ignores when it runs. The logic, table names, conditions, and results stay identical. The Minify button does the reverse, collapsing the query onto one line, and that is also behaviour-preserving.

Is my SQL sent to a server?

No. All formatting happens in your browser using JavaScript. Your queries never leave the page, are never logged, and are discarded when you close the tab, which makes the tool safe to use with production schema names and internal table structures.

Why should I format SQL at all?

Readable SQL is faster to review, debug, and hand off. Putting each major clause on its own line makes the query structure visible at a glance, so you can spot a missing JOIN condition or a misplaced WHERE filter that a one-line query would hide. Consistent formatting also reduces noise in code review diffs.

Can it minify as well as beautify?

Yes. The Format button expands the query with indentation and line breaks for reading, while the Minify button collapses all extra whitespace into a single compact line, which is handy for embedding a query in code or a config string. Both run entirely client-side.

IT
India Tools Editorial
Calculators & explainers maintained by the India Tools team.