SQL Formatter

Paste a SQL statement or a script. Keywords are written in upper case, each clause starts its own line and the conditions and columns are indented. Nothing you paste leaves your browser.

Free Runs in your browser Checked Tuesday, November 10, 2026

One statement or several, separated by semicolons. Strings, comments and quoted names are kept as they are.

Indentation

Removes the line breaks and the indentation.

Result

Formatted SQL — Copy it, or download it as formatted.sql.
Statements — How many statements the text holds.
Formatted SQL

This tool runs in your browser. What you enter is not sent to us.

How to use it

  1. Paste the statement into SQL. The layout is made as you type.
  2. Choose an Indentation of 2 or 4 spaces for the layout.
  3. Tick Minify: all on one line if the statement must be a single line, for a config file or a log.
  4. Copy the Formatted SQL, or download it as formatted.sql.

How the layout is made

The formatter reads the text as tokens: words, numbers, strings, quoted names, comments, operators and punctuation. Words of the SQL keyword list are written in upper case, and the rest, names included, keep the spelling they had. A clause such as SELECT, FROM, WHERE, GROUP BY, HAVING or ORDER BY starts a new line, and its content is indented one step under it.

Inside SELECT, FROM, GROUP BY, ORDER BY, SET and VALUES, each comma starts a new line. AND and OR start a line under WHERE, HAVING and ON. A join such as LEFT OUTER JOIN starts a line under FROM, and its ON condition stays on that line. A subquery in parentheses is indented one step deeper than the line on which its parenthesis stands, and its closing parenthesis lines up with that line.

  • Strings with doubled quotes, quoted identifiers in double quotes, backticks or square brackets, and dollar-quoted text are kept exactly.
  • Line comments and block comments are kept. When the layout is minified, a line comment becomes a block comment so that the statement can stay on one line.

What the formatter does not do

The formatter does not parse the statement, so it does not check that it is valid SQL and does not change what it means. It does not know the rules of a particular database, so a keyword that is special in one dialect and an ordinary name in another is written in upper case in both cases. Check the result with your own database before you use it in production.

Worked example: a report query

The default statement selects the id and name of active users with the number of their orders, groups them and sorts by the count. Formatted with two spaces, the select list has one column per line, each clause starts its own line, and LIMIT 10 is the last line.

Minified, the same statement is one line with single spaces between the words. The count shows 1 statement.

Frequently asked questions

Which SQL dialect does the formatter support?

It works for the parts that most dialects share, such as SELECT, INSERT, UPDATE, DELETE, joins, subqueries and CASE. It accepts the quoting styles of MySQL, PostgreSQL, SQL Server and SQLite, but it does not check dialect-specific syntax.

Will formatting change the result of my query?

No. Only the spaces, line breaks and the case of the keywords change. Names, strings, numbers and comments are kept exactly, so the statement means the same thing.

Why did a word in my table or column name change to upper case?

The word is on the keyword list, such as USE or ORDER, so it is written in upper case wherever it stands. Names that are not on the list are kept exactly. Quote such a name with double quotes or backticks to keep it as typed.

Why does a line comment become a block comment when minified?

A line comment ends at the end of its line, so on one line it would hide the rest of the statement. The block comment keeps the text and does not hide the code after it.

Is my SQL sent to a server?

No. The formatting runs in your browser. Nothing you paste is sent to our server or stored there, which matters when the statement holds private data.

Sources

Figures and text last checked on Tuesday, November 10, 2026.

We use necessary cookies to run the site. With your consent, Google also uses advertising cookies to show personalised ads. If you reject them, you still see ads, but they are not personalised.