TTKTheTextKit

SQL Formatter and Beautifier

Paste a SQL query, or several separated by semicolons, and get it back with one clause per line, indented joins and conditions, and keywords in the case you choose. Pick your database from the dialect list so its own syntax is read correctly. Your queries never leave your browser, which matters when they contain table names, customer data or production details.

Formatted SQL
SELECT
  o.id,
  c.name,
  sum(i.qty * i.price) AS total
FROM
  orders o
  JOIN customers c ON c.id = o.customer_id
  LEFT JOIN items i ON i.order_id = o.id
WHERE
  o.created >= '2026-01-01'
  AND c.country IN ('US', 'CA')
GROUP BY
  o.id,
  c.name
HAVING
  sum(i.qty * i.price) > 100
ORDER BY
  total DESC
LIMIT
  20;

Related Tools

[5 suggestions]

About the SQL Formatter and Beautifier

The SQL Formatter lays out a query so that it can be read: SELECT, FROM, WHERE, GROUP BY and ORDER BY each start a line, columns and conditions are indented, joins and subqueries are nested, and keywords can be set to upper case, lower case or left as typed. It changes only whitespace and the case of keywords. Strings, quoted names and comments are kept exactly as you typed them. Every database has its own syntax, so the tool offers 13 dialects, including PostgreSQL, MySQL, SQL Server, Oracle, SQLite, BigQuery and Snowflake. If the dialect you chose cannot read your query, the tool tries PostgreSQL, MySQL and SQLite and tells you which one it used, and if none can, it shows the error. Choose the dialect of your database for the most faithful result, because a dialect that does not know a symbol of another database can split it apart: for example, the Spark and BigQuery rules do not read a doubled quote inside a string the way standard SQL does. We tested the formatter on 1,434 queries and data statements written for SQLite, checking that SQLite's own compiled form of each query was identical before and after formatting, and the result was identical every time with the SQLite, PostgreSQL, MySQL and several other dialects. Formatting an already formatted query changed nothing. The formatting is done by the open source sql-formatter library, and everything runs in your browser.

How do I format a SQL query?▾

Paste the query into the box. The tool puts each clause on its own line, indents columns and conditions, and sets the keyword case you choose. Select your database in the Dialect list so its own syntax is understood, then copy the result or download it as a .sql file.

Does formatting change what a query does?▾

It should not. The tool changes only spaces, line breaks and the case of keywords, and keeps strings, quoted names and comments exactly as typed. In our test on 1,434 SQLite queries the compiled form of every query was identical after formatting. Use the dialect of your database to be safe, because a dialect that does not know your syntax can split a symbol apart.

Which SQL dialects are supported?▾

Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Snowflake, Amazon Redshift, Spark SQL, Trino and IBM Db2. If the one you pick cannot read a query, the tool tries PostgreSQL, MySQL and SQLite and says which it used.

Should SQL keywords be upper case or lower case?▾

Neither is required, because SQL ignores the case of keywords. Upper case is the long-standing convention and makes keywords stand out from table and column names, while many teams now prefer lower case. Choose either in the Keywords list, or keep the case as typed.

Is my SQL uploaded?▾

No. The formatting runs in your browser and your queries are not sent anywhere or stored.