TFT

Free SQL Formatter & Beautifier Online

Clean up messy SQL code instantly with our free formatter. Make your queries readable and maintainable with proper indentation and keyword highlighting. Supports all major SQL dialects.

SQL Formatter & Minifier

Format SQL queries for readability or minify them for production use.

1 lines
Formatted output will appear here...
0 characters
Minified output will appear here...

How it works

Paste a query and the formatted version appears next to it as you type. The formatter is a lightweight, rule-based text pass, not a full SQL parser. It starts a new line before common keywords such as SELECT, FROM, WHERE, JOIN, ON, AND, OR, GROUP BY, ORDER BY, HAVING, LIMIT and UNION. It also breaks after every comma, puts single spaces around comparison operators like = and <>, and tidies spacing inside parentheses.

Indentation follows parentheses. Every opening bracket pushes the following lines in by two spaces, and every closing bracket pulls them back. That makes subqueries, IN lists and function arguments easy to see at a glance.

A second output, the minified version, removes line and block comments and squeezes whitespace into a single line. Both outputs have their own copy button.

When this is useful

The most common case is a query pulled out of an application log, an ORM debug trace or a slow-query report, where it arrives as one long line. Splitting it into clauses lets you see the join order and filters before you dig into performance.

It also helps when you are tidying a snippet for a pull request, a README or a support ticket, or when you are learning SQL and want to see how a long statement is built from clauses. The minifier is handy for pasting a query into a config value or an environment variable.

What to know

Because the rules are text-based, they cannot tell a keyword from the same word inside a string literal or a quoted identifier. A value like 'Order, by hand' may get extra line breaks, and a column called order or limit may be split. Check the output when your query contains string values.

Keywords are not re-cased, there is no indentation setting, and the tool does not report syntax errors. If you need to know whether a query is valid, use the SQL query validator instead. Procedural code such as stored procedures, CASE blocks nested several levels deep or dialect-specific extensions may need manual touch-ups.

Minifying removes comments, so do not minify a query whose comments hold hints your database reads, such as optimizer hints in MySQL or Oracle.

Common questions

Does it change my keyword case?

No. Keywords keep whatever case you typed. If you want SELECT and FROM in uppercase, run the output through the SQL case converter.

Does formatting change what the query does?

It only moves whitespace, so the query should run the same. Because the rules are simple text patterns, always run a quick check on anything critical before shipping it.

Is my SQL uploaded anywhere?

No. Formatting and minifying run in your browser, so queries with real table names stay on your machine.

Which dialects work?

There is no dialect setting. The tool looks for common keywords shared by MySQL, PostgreSQL, SQL Server and SQLite, so vendor-specific syntax is treated as plain text.

What does Copy Minified do?

It strips -- and /* */ comments and collapses all whitespace to single spaces, giving you a compact one-line query.