DevToolPal
EN

SQL Formatter

Beautify SQL queries for MySQL, PostgreSQL, SQL Server, Oracle, SQLite, BigQuery and more.

Runs locally, never uploaded

Options

Input

0 chars · 0 B

Output

0 chars · 0 B

What it does

The SQL formatter turns a long, single-line query into a readable, consistently indented one. Each clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) starts on its own line, selected columns and conditions are listed one per line, joins line up under the table they join, and subqueries are indented inside their parentheses.

Formatted SQL is easier to review in pull requests, to debug when a query returns the wrong rows, and to paste into documentation. It also helps when you copy a query out of an ORM log or an application error message, where everything is on one line.

How to use

  1. Paste one or more SQL statements into the Input box, drop a .sql file on it, or click Sample.
  2. Pick the Dialect of your database.
  3. Choose Keywords in UPPERCASE, lowercase, or keep them as typed. Function names such as COUNT follow the same setting.
  4. Pick 2 spaces, 4 spaces or tabs for Indent.
  5. Copy the result or download it as a .sql file. Shortcuts: Ctrl/Cmd+Enter formats, Ctrl/Cmd+Shift+C copies.

Several statements separated by semicolons are kept apart with a blank line. Comments stay where they are.

Example

select u.id, count(o.id) as orders from users u left join orders o on o.user_id = u.id group by u.id

becomes

SELECT
  u.id,
  COUNT(o.id) AS orders
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
GROUP BY
  u.id

Tips

Upper-case keywords make clauses stand out from table and column names, which is the most common team convention. If your team writes lowercase SQL, choose lowercase and the whole query will match. If the formatter reports an unexpected token, check that the dialect is right: for example, backtick-quoted names are valid in MySQL but not in standard SQL.

FAQ

› Is my SQL sent to a server?

No. The formatter runs in your browser, so queries that reveal table names, customer data or business logic stay on your device.

› Which SQL dialects are supported?

Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Snowflake, Redshift and Spark SQL. Choosing the right dialect helps with dialect-specific syntax such as backtick identifiers, :: casts or square-bracket names.

› Does formatting change what the query does?

No. Only whitespace and, if you choose, the letter case of keywords and function names change. Identifiers, string literals and comments are kept exactly as written.

› Why do I get "Unexpected end of input"?

A bracket or a quote is usually not closed. The error points at the end of the query; look for the last opening ( or ' that has no partner.