Allin1Tool
Developer ToolsRuns in your browser

SQL Formatter

Format SQL for 10 dialects with keyword, identifier and function casing, comma placement and indent control. Nothing is executed.

Share:

SQL Formatter workspace

Selects the keyword set used for casing.

Quoted names are always left alone.

Source Editor

Input

Press Ctrl/Cmd + Enter to run.

Your draft is kept in this tab only (sessionStorage) and disappears when the tab closes. .

Result Console

1
 

Using SQL Formatter

  1. Paste your query and pick the Dialect that matches your database.

  2. Set casing for Keywords, Identifiers and Functions, and choose an indent of 2 spaces, 4 spaces or Tab.

  3. Adjust comma position, stacked or inline lists, and the maximum line length to suit your house style.

  4. Press Format SQL, then copy the highlighted result or tick Compact output for a single-line version.

The query is tokenised before anything is rearranged, so strings, comments and quoted identifiers are recognised for what they are and never recased. Ten dialects contribute genuinely different keyword sets, and CREATE PROCEDURE parameters are aligned into a column so long signatures stay readable.

This page reindents a query and adjusts its capitalisation. That is the entire remit, and the boundary matters: no connection is opened, no query is executed, and no result set exists. A formatter that runs your SQL would be a very different and much more dangerous thing.

Quoted identifiers survive intact

This is the part that determines whether the output is usable. Every SQL product has its own way of quoting a name that would otherwise collide with a keyword or contain a space:

Quoting styleWhere it is used
BackticksMySQL, MariaDB, BigQuery, Spark SQL
Square bracketsSQL Server, SQLite
Double quotesPostgreSQL, Oracle, standard SQL

The tokeniser recognises all three and treats what is inside them as a literal name, never as a keyword. Recasing a quoted identifier is not a cosmetic change — in PostgreSQL, "userId" and "userid" are different columns, and rewriting one into the other produces a query that fails or, worse, hits the wrong column. The earlier build uppercased backtick and bracket names, so a MySQL query came back referring to a table that did not exist.

Session variables beginning with @ and temporary tables beginning with # are recognised too, so T-SQL survives the trip.

The dialect selector changes the keyword set

Ten dialects are offered, and choosing one swaps in that product's keywords on top of the standard set. QUALIFY and UNNEST are keywords in BigQuery; ILIKE and RETURNING in PostgreSQL; NOLOCK, PIVOT and APPLY in T-SQL; ROWNUM, DUAL and NVL in Oracle; DISTKEY and SORTKEY in Redshift. Pick the wrong dialect and the layout is still correct, but words specific to your product get treated as ordinary identifiers and miss the keyword casing. In the previous build the dropdown was decorative and every dialect produced identical output.

Layout controls

Keywords, Identifiers and Functions each get their own casing selector — uppercase, lowercase, capitalised or preserved. Set identifiers to preserve, which is the default, unless you have a specific house style; quoted names are left alone either way.

Indent is 2 spaces, 4 spaces or a tab. Comma position puts the separator after each item or leading before the next one — leading commas make it obvious which line you forgot when a column list grows. Lists stacks each selected column on its own line or keeps short lists inline. Max line length decides when an inline list has to break, between 40 and 240 characters.

Remove linebreaks first flattens the input before reformatting, which is what you want when the query arrived out of a log file with arbitrary wrapping. Compact output tightens the result for pasting into a single-line configuration field.

CREATE PROCEDURE and ALTER PROCEDURE get special handling: parameters are aligned in a column so a long signature stays readable. The result is shown with syntax highlighting, so a misplaced quote is visible at a glance.

Formatting does not change what a query does

Whitespace and case are invisible to a query planner. Reformatting will not make a statement faster or slower, and it will not change its results. If you are chasing performance, EXPLAIN is the tool; readability is how most people find the missing join predicate that turned an inner join into a cross product.

What was removed

A previous build shipped a fake in-memory database — around 720 lines of hardcoded tables and a toy query interpreter — which ran on every page load whether or not anyone asked it to. It answered a handful of SELECT shapes and invented results for everything else, which is worse than useless when someone is checking a query they intend to run for real.

To lay out a payload one of these queries returns, JSON Formatter handles the document side of the same job.

Your query is tokenised in this tab and posted nowhere. Since what gets pasted here often contains a schema, a table you would rather not name publicly, or credentials in a connection comment, that is worth stating plainly: the draft lives in sessionStorage until the tab closes.

Frequently asked

What does choosing a dialect actually do?

It swaps in that product's keyword list on top of the standard set, so QUALIFY and UNNEST are recognised for BigQuery, ILIKE and RETURNING for PostgreSQL, NOLOCK and APPLY for T-SQL, ROWNUM and DUAL for Oracle. Pick the wrong one and the layout is still right, but product-specific words miss the keyword casing.

Will it change the case of my quoted column names?

Never. Backtick, square-bracket and double-quoted names are treated as literal identifiers, because in PostgreSQL a quoted name is case-sensitive and rewriting it points the query at a different column. An earlier build uppercased backtick and bracket names, which produced queries that failed outright.

Can this tool run my query?

No. It only rearranges text — no connection is opened and no result set exists. A previous build shipped a fake in-memory database that invented answers to queries; it has been deleted.

Does formatting affect query performance?

Not at all. Whitespace and capitalisation are invisible to the planner, so the same statement runs identically before and after. What formatting buys you is readability, which is how most people find the missing join predicate that turned an inner join into a cross product.