SQL Formatter

Format and minify SQL queries with dialect awareness: SQL Server, MySQL, PostgreSQL, Oracle and SQLite.

Text

            

I colori sono negli attributi style, quindi il frammento resta colorato ovunque lo incolli senza portarsi dietro un foglio di stile.

Why the dialect changes the outcome

It looks like a cosmetic detail but it decides how the text is read. In SQL Server [Order] is a quoted column name; in MySQL square brackets delimit nothing and that same text means something else. The hash sign opens a comment in MySQL and in no other dialect. A formatter ignoring these differences would not produce an ugly query — it would produce a broken one.

How clauses are laid out

Major clauses open a line at the current depth; JOINs break onto their own line but stay aligned with the FROM above them; conditions joined by AND and OR are stacked and indented, so a WHERE with six conditions is read by scanning rather than searching. Parentheses increase indentation, because a subquery is a query inside another and the shape should say so.

Strings are left alone

Text inside quotes and block comments stays exactly as it is. That is why a real tokeniser is needed rather than a series of replacements: a keyword inside a string is content, not structure, and reformatting it would change what the query does.

The batch separator

GO is not SQL: it is a SQL Server client command marking the end of a batch. That is why it is isolated on its own line and resets indentation, rather than being treated as an ordinary keyword.

What it does not do

It formats, it does not analyse: it does not check that the query is valid, it does not know your tables and it does not rewrite your code. On very dialect-specific constructs it may lay out lines differently from how you would have: the meaning stays the same, the appearance does not.

Frequently asked questions

Because it changes how the text is interpreted. [Order] is a quoted identifier in SQL Server but not in MySQL, and the hash sign opens a comment only in MySQL. Picking the wrong dialect can break the query.

No. A query often contains table names and values from an internal system: everything runs in your browser and nothing is transmitted.

No, it only formats. It does not know your tables and does not check syntax: a query with a mistake gets reformatted, not flagged.

Related tools