U
UseCalcForge Free Online Calculators
Developer Tools

SQL Formatter.

Paste a SQL query and get it back indented, with keywords uppercased and each clause on its own line. Or minify it to one line.

Reviewed by the UseCalcForge editorial desk | Last updated
Good to know

It formats, it does not check.

The formatter rearranges whitespace and keyword case only. It will happily format a query with a missing comma or a misspelled column, and the problem is often easier to spot once the query is laid out. Your query is sent to our server to be formatted and is not stored.

MySQL PostgreSQL SQL Server SQLite

Processed on our server. What you enter is sent over an encrypted connection, calculated, and returned. It is never written to a database or logged, and nothing is retained once the result is sent. Avoid entering passwords, API keys or other secrets. How we handle data

What Prettify does

Each clause (SELECT, FROM, WHERE, GROUP BY…) starts a new line with its contents indented beneath it. Column lists break at commas, AND/OR conditions go on their own lines, JOINs line up under FROM, and subqueries are indented a further level.

What it leaves alone

Text inside quotes is never touched, so 'in stock' stays exactly as typed. Quoted identifiers, numbers, bind parameters such as :id or $1, and your table and column names keep their original case.

Knowledge Base

Formatting SQL So It Can Be Read Methodology.

SQL copied out of an ORM log, a BI tool or a colleague's message usually arrives as one enormous line. This formatter breaks it into one clause per line with consistent indentation, so you can see at a glance which conditions belong to the WHERE clause, which tables are joined, and where a subquery begins and ends. The minify option does the reverse, collapsing a query to a single line for a config file or a log statement.

The Calculation Branch

Prettify: clause keyword on its own line → contents indented 4 spaces → one list item or condition per line

Industrial Standards.

The query is split into tokens: keywords, names, numbers, operators, quoted strings and comments. Strings and quoted identifiers are kept as single tokens, so nothing inside quotes can be mistaken for a keyword. A fixed list of SQL keywords is uppercased; everything else keeps its original case. Line breaks are then inserted before major clauses, list commas and AND/OR conditions at the top level of each clause. A parenthesis followed by SELECT or WITH is treated as a subquery and indented; other parentheses, such as function calls and IN lists, stay on one line. The BETWEEN … AND pairing is recognised so it is not split. Processing happens on our server and the query is not stored.

In-Depth Analysis & Reference Data

Why the layout helps. Most SQL bugs hide in precedence and scope: an OR that was meant to be grouped with the AND above it, a condition that belongs in a JOIN's ON clause but sits in the WHERE clause (turning a LEFT JOIN into an inner join), or a column in the SELECT list that is missing from GROUP BY. With each condition on its own line those mistakes become visible. A query like WHERE a = 1 AND b = 2 OR c = 3 is laid out as three separate lines, which makes it obvious that it needs parentheses.

Comments. When prettifying, -- and /* */ comments are kept in place. When minifying they are removed, because a -- comment would otherwise swallow everything after it once the query is on a single line.

Dialects. The formatter does not need to know which database you use, because it only changes layout. Backtick identifiers (MySQL), double-quoted identifiers (PostgreSQL), :: casts and JSON operators such as -> and ->> all pass through unchanged. SQL Server square-bracket identifiers such as [order id] are kept intact, spaces included.

Before pasting from production. Your query leaves your machine to be formatted. It is not logged or stored, but if it contains real customer data in literal values, or credentials, replace those with placeholders first.

Frequently asked questions.

Will formatting change what my query does?

No. Only whitespace and the letter case of SQL keywords change, and SQL treats keywords the same in any case. String literals, quoted names and the order of every token are preserved.

Does it find syntax errors?

No. It does not parse the query against any database's grammar, so invalid SQL is formatted just like valid SQL. Run the query, or use EXPLAIN, to check it. The indented layout does make missing commas and unbalanced parentheses much easier to spot by eye.

Can I format several statements at once?

Yes. Separate them with semicolons and each statement is formatted on its own, with a blank line between them. Very long migration files are better handled by a formatter built into your editor.

Estimates for planning. Always confirm against an authoritative source.