Database & SQL tools

SQL formatterRead queries, preserve their text

Read queries, preserve their text

SQL formatter

Current SQL

Format and minify read this document and write the result back. Pasting, typing, and changing dialect, indentation, or keyword case do not rewrite it. Viewing the syntax tree does not replace the SQL.

Ctrl/Cmd+Enter: FormatCtrl/Cmd+Shift+Enter: Minify

Enter SQL or choose an example.

Dialect and presentation

No connection, schema lookup, permissions check or EXPLAIN runs here. Successful formatting is not syntax validation; even a successful AST parse cannot prove a query works against your database. Only structural keywords change case; contextual words such as ACTION or NO keep their source spelling to protect identifiers.

AST accepts decimal integers and ordinary decimals with at most 15 significant digits. Exponents and hexadecimal numbers are rejected in that mode. Numeric nodes must match source values; formatting and compact output retain original precision. The AST mode uses a separate parser for four dialects. Oracle formatting remains available, while Oracle AST is explicitly unsupported. A tree is a parser interpretation, not an execution plan. Decimals need a digit before the point (use 0.5, not .5).

The first input allows 100,000 UTF-16 units, 20,000 tokens, 50 parenthesis levels and 200 statements. A generated document can continue up to 1,000,000 units. The syntax tree allows 5,000 tokens and 30 levels.

Original

Processed locally in your browser. No database connection or saved history. Undo and redo cover edits, formatting, minifying, the example, clearing, and restoring the original. Options are not history steps.

The SQL formatter helps you review a long query before changing it in your editor. Choose the dialect that produced the source: formatting rules differ even when the SELECT statements look similar.

Use the SQL beautifier to reveal joins and nested clauses, or the SQL minifier to reduce whitespace while retaining comments. You can format SQL online without turning a formatting success into an execution guarantee.

Why use this SQL formatter?

Follow a query through its clauses

The SQL formatter separates clauses and applies consistent indentation. Quoted text, numeric spellings and comments are checked against the source; an unsafe rewrite is rejected instead of silently exported.

A dense query becomes indented rows while colored literal and comment blocks remain intact.

Inspect structure separately from presentation

The AST mode uses a separate parser for four dialects. Oracle formatting remains available, while Oracle AST is explicitly unsupported. A tree is a parser interpretation, not an execution plan.

A query branches into a syntax tree beside an independent formatted text panel.

Choose the interpretation before the style

01

Select the actual dialect

MySQL, PostgreSQL, SQLite, SQL Server and Oracle have different quoting rules. Selecting PostgreSQL does not translate a MySQL query; it changes the grammar used for the operation.

02

Format, minify, or inspect

Format and minify write the current document. Indentation and keyword case apply only to the next action. The syntax tree is a separate read-only view and has stricter numeric and complexity limits.

03

Act on the text you see

Pasting and changing options do not rewrite the document. Ctrl/Cmd+Enter formats, and Shift minifies. Undo restores the previous document, including manual edits.

Formatting and parsing with separate responsibilities

Five formatting dialects

Use sql-formatter with two spaces, four spaces or tabs and uppercase, lowercase or original keywords. Identifier, function and datatype case are left unchanged by configuration. Only structural keywords change case; contextual words such as ACTION or NO keep their source spelling to protect identifiers.

Comment-preserving compact output

Whitespace outside tokens is reduced without deleting line comments, block comments or executable hints. PostgreSQL newline-separated string literals keep their required separation.

A bounded syntax tree

node-sql-parser handles its supported MySQL, PostgreSQL, SQLite and Transact-SQL subset. JSON exports contain only the returned tree, never the editor history or previous input. Viewing the tree does not replace the current SQL.

What these operations cannot prove

No database execution
No connection, schema lookup, permissions check or EXPLAIN runs here. Successful formatting is not syntax validation; even a successful AST parse cannot prove a query works against your database.
Grammar has limits
Stored procedures, triggers, function definitions, BEGIN/DECLARE blocks, GO batches, custom DELIMITER commands, templates and client meta commands are outside scope. Oracle supports formatting but not AST.
AST numbers are checked
AST accepts decimal integers and ordinary decimals with at most 15 significant digits. Exponents and hexadecimal numbers are rejected in that mode. Numeric nodes must match source values; formatting and compact output retain original precision. Decimals need a digit before the point (use 0.5, not .5).
Comments may retain line breaks
Compact does not promise a single line. Removing a newline after -- can comment out a following statement. Hints and executable comments remain text; their database effect is not inspected.
Explicit resource budgets
The first input allows 100,000 UTF-16 units, 20,000 tokens, 50 parenthesis levels and 200 statements. A generated document can continue up to 1,000,000 units. The syntax tree allows 5,000 tokens and 30 levels.

SQL formatter questions

How should I format SQL queries?

Choose a stable dialect and indentation style so joins, conditions and subqueries are easier to review. This SQL formatter separates presentation from AST inspection; always review a changed query in the context of its database.

Is there a reason to uppercase SQL keywords?

Uppercase keywords can make clauses visually distinct, but this is a style convention. Choose lowercase or preserve if that matches your project. Quoted identifiers and string content are not converted to uppercase.

Can I tidy SQL without adding so many lines?

Choose compact output. It collapses outside whitespace while preserving tokens and comments, including line breaks needed for line comments or PostgreSQL adjacent string literals. It is intentionally less aggressive than a comment-removing minifier.

Can I check whether a MySQL query is valid without executing it?

AST mode can report whether this parser accepts its grammar. It cannot check tables, column types, permissions or server-specific behavior. A formatter result alone gives even less assurance: it is a layout operation.

Why do client meta commands break SQL formatters?

Commands such as psql backslash commands belong to the database client, not ordinary SQL grammar. Remove them from the snippet you format, keeping the original script separately; this tool does not interpret them.

Found a formatting problem?

Review your next query

Use the SQL formatter on the current document: format or minify writes it back, and a supported syntax tree stays read-only.