SQL Formatter & Beautifier

Developer Tools

Paste a SQL query and get it laid out with consistent indentation and keyword case, for the database dialect you use.

Options
Input
Output

Processed in your browser. A copy of each run is saved to your past runs so you can reopen it. Privacy

About

What the SQL Formatter does

The SQL Formatter, or SQL beautifier, puts each clause of a query on its own line, indents the column lists, joins and conditions under it, and applies one keyword case. It knows the syntax of Standard SQL, PostgreSQL, MySQL, SQL Server (T-SQL), SQLite, BigQuery and Snowflake, and can minify a query to one line. It is for developers, analysts and DBAs reviewing or sharing SQL. It never connects to a database or runs the query.

Steps

How to use it

  1. 1Paste one or more SQL statements into the Input panel, or upload a .sql file.
  2. 2Choose the dialect your database uses, plus keyword case, indent and comma style in the Options strip.
  3. 3Press Format (or Cmd/Ctrl+Enter). Press Minify instead to get a single line without comments.
  4. 4Copy the result or download it as query.sql from the Output header.

Example

A real run

Input

select o.id, c.name, sum(oi.qty * oi.price) as total from orders o join customers c on c.id = o.customer_id join order_items oi on oi.order_id = o.id where o.created_at >= '2026-01-01' and c.state = 'TX' group by o.id, c.name order by total desc limit 10;

Output

SELECT
  o.id,
  c.name,
  sum(oi.qty * oi.price) AS total
FROM
  orders o
  JOIN customers c ON c.id = o.customer_id
  JOIN order_items oi ON oi.order_id = o.id
WHERE
  o.created_at >= '2026-01-01'
  AND c.state = 'TX'
GROUP BY
  o.id,
  c.name
ORDER BY
  total DESC
LIMIT
  10;

PostgreSQL dialect, uppercase keywords, 2-space indent. Each clause starts a line, the joins sit under FROM and the two conditions under WHERE. The function name sum and the column names keep their original case.

Options

Every setting, and when to use it

Dialect
Standard SQL, PostgreSQL, MySQL, SQL Server (T-SQL), SQLite, BigQuery or Snowflake. The dialect decides which syntax is understood: T-SQL brackets like [dbo].[Orders] and TOP, PostgreSQL :: casts and $$ function bodies, BigQuery backtick names. Pick the database the query was written for.
Keywords: UPPERCASE, lowercase or as written
Uppercase keywords (SELECT, FROM, WHERE) are the most common house style and make clauses easy to scan. Lowercase matches some style guides. As written leaves keywords alone. Table names, column names and string literals are never re-cased.
Indent: 2 spaces, 4 spaces or tab
How far columns, join lines and conditions sit under their clause. Match your repository's other SQL files.
Commas: trailing or leading
Trailing puts the comma at the end of each line, the default almost everywhere. Leading starts each following line with a comma, a style some teams use so adding or commenting out the last column touches only one line.
Blank lines between queries
With several statements separated by semicolons, put 0, 1 or 2 empty lines between them.
Minify
Collapses the query to one line and removes -- and /* */ comments, leaving string literals, quoted names and PostgreSQL dollar-quoted bodies untouched. Useful for log lines, connection-string tests and code that needs the query on one line.

Good to know

Common problems and limits

The formatter only rearranges whitespace and keyword case. It does not check that tables or columns exist, run the query, or change its results.

When the query uses syntax the chosen dialect does not know, the tool reports where it stopped, for example "Could not parse "[" at line 1, column 27", and shows the query unchanged. Square-bracket names in PostgreSQL mode are the usual cause; switching to SQL Server fixes that one.

Minify removes all comments, including optimizer hints written as /*+ … */ comments in Oracle or MySQL. Keep those queries formatted instead of minified.

Input is limited to 2 MB. Very long generated statements (thousands of inserted rows) format correctly but produce long output; minify them if you only need them on one line.

Audience

Who uses it

  • Backend developersMake an ORM-generated query from a log readable before working out why it is slow, then compare two versions with Text Compare.
  • Data analystsTidy a long reporting query before sharing it in a pull request, a dashboard description or a Slack thread.
  • DBAsStandardize keyword case and indentation across a folder of migration scripts so reviews show real changes only.
  • Ecommerce and operations teamsRead the query behind a store report (orders, refunds, inventory by state) without editing it in a database tool, and move results between formats with the CSV to JSON converter.
  • StudentsSee how SELECT, JOIN, WHERE and GROUP BY fit together in queries copied from tutorials.

FAQ

Frequently asked

What is a SQL beautifier?

A SQL beautifier, or SQL formatter, rewrites a query with each clause on its own line, consistent indentation and one keyword case, so the logic is easy to follow. It changes only whitespace and the case of keywords; the query does exactly the same thing. This page supports seven dialects and runs in your browser.

How do I beautify a SQL query?

Paste the query above, choose the dialect your database uses, and press Format. Pick uppercase or lowercase keywords and leading or trailing commas if you have a house style, then copy the result. The same steps work for several statements at once.

Does formatting SQL change the query results?

No. Only whitespace and keyword case change, and SQL keywords are case-insensitive. String literals, quoted identifiers and comments are left exactly as written, so the database receives the same query. Minify removes comments, which matters only if a comment holds an optimizer hint.

Should commas go at the start or the end of the line?

Both are valid SQL. Trailing commas are the most common style and read like ordinary text. Leading commas line up at the left edge, so adding, removing or commenting out the last column changes one line instead of two. Pick one per codebase; this tool does either.

How do I format SQL in VS Code?

VS Code has no built-in SQL formatter. Install an extension from the marketplace (search for SQL formatter), then run Format Document with Shift+Alt+F on Windows or Shift+Option+F on Mac. Without an extension, paste the query here and copy the formatted version back.

How do I format SQL in SQL Server Management Studio?

SSMS does not include a full SQL formatter. Paid add-ins such as Redgate SQL Prompt add one, or you can paste the query here with the dialect set to SQL Server (T-SQL), format it and paste it back into SSMS.

Why does it say it could not parse my query?

The query contains syntax the chosen dialect does not understand, often square-bracket names (SQL Server), backtick names (MySQL or BigQuery) or a vendor-specific function. The message gives the line and column. Choose the dialect your database uses and format again; the query is never changed when parsing fails.

Automation: an MCP tool format_sql(sql, dialect, keywordCase) → sql and an n8n node are planned for this tool.

Built and maintained by Radhika SinghLast updated Questions: hello@operativez.ai