SQL Formatter

Free dialect-aware SQL formatter and beautifier for T-SQL (SQL Server), PostgreSQL, MySQL, MariaDB, Oracle PL/SQL, and SQLite. Paste a query, pick your dialect, and get consistently indented, readable SQL. Everything runs in your browser; nothing is uploaded.

Formatted SQL

Formatting changes whitespace, line breaks, and keyword casing only — string literals, identifiers, and comments are never modified, so the formatted query behaves exactly like the original.

Why dialect matters when formatting SQL

SQL dialects disagree on syntax a formatter must parse before it can re-indent anything. A formatter that only knows generic SQL will trip over — or silently mangle — constructs that are perfectly valid in your database:

  • SQL Server / T-SQL — bracketed identifiers like [dbo].[Order Details], TOP 10, table hints, and variables with @ prefixes. A generic parser can read […] as something other than an identifier and break the statement apart mid-name.
  • PostgreSQL — dollar-quoted strings ($$…$$ function bodies), the :: cast operator, and operators like ->> for JSON. Dollar quoting in particular confuses formatters that treat $ as an ordinary character.
  • MySQL / MariaDB — backtick-quoted identifiers (`order`), which a generic grammar may not recognize as quoting at all.
  • Oracle PL/SQL — packages, anonymous BEGIN … END; blocks, and q'[…]' alternative quoting, which need a procedural-aware grammar rather than a statement-by-statement one.

This tool uses the open-source sql-formatter library with a separate grammar per dialect, so picking the right dialect above means these constructs are parsed — and preserved — correctly.

What this formatter does — and doesn't — do

It formats: normalizes whitespace and line breaks, indents clauses consistently, and optionally converts keyword casing. String literals, identifiers, numeric values, and comments are passed through untouched, so the output is the same query, just readable.

It does not validate or execute your SQL. A query that formats cleanly can still fail at runtime — wrong column names, missing permissions, type errors — and conversely, syntactically invalid SQL may fail to format at all. When the parser can't make sense of the input you'll see the parse error in the status line and the previous output is kept. It also doesn't rewrite queries: no alias expansion, no SELECT * resolution, no dialect translation.

Frequently asked questions

How do I format T-SQL / SQL Server queries online?

Select SQL Server / T-SQL as the dialect, paste your query, and the formatted result appears as you type. The T-SQL grammar understands bracketed identifiers like [dbo].[Users], TOP clauses, and T-SQL-specific keywords, so they survive formatting intact — a generic formatter can misparse them.

Does formatting change what my query does?

No. Formatting only changes whitespace, line breaks, and keyword casing. String literals, identifiers, numbers, and comments are left untouched, so the formatted query is semantically identical to the original.

Is my SQL uploaded to a server?

No. The formatter runs entirely in your browser using the open-source sql-formatter library — your SQL never leaves your machine, so it is safe to format queries that contain sensitive table names or embedded data.

Which SQL dialects are supported?

Seven grammars: generic SQL, SQL Server (T-SQL), PostgreSQL, MySQL, MariaDB, Oracle PL/SQL, and SQLite. Pick the dialect that matches your database so dialect-specific syntax — brackets, backticks, casts, dollar-quoting — is parsed correctly.

Can I choose keyword casing and indentation?

Yes. Keywords can be converted to UPPERCASE, lowercase, or left exactly as you wrote them, and indentation can be 2 spaces, 4 spaces, or tabs. The output updates live as you change any option.

What happens if my SQL has a syntax error?

The formatter parses your SQL to understand its structure, so severely malformed SQL may fail to format. When that happens the parse error is shown below the output and the last successful result is kept — the tool formats SQL, it does not validate or execute it.

Formatting queries in a browser tab all day?

Jam SQL Studio is a free desktop SQL client for SQL Server, PostgreSQL, MySQL, Oracle, and SQLite — with format-on-demand right in the editor, plus IntelliSense that understands your schema.

Free for personal use • No account required • Mac, Windows, Linux

More free SQL tools