go-supertools
Developer & Data Tools

SQL Beautifier

Format SQL queries with clean indentation and optional uppercase keywords.

Runs in your browser Your input never leaves your device.

Report a problem with this tool

About this tool

Paste a SQL statement and the tool puts each clause on its own line with indented column lists, using the sql-formatter library. Choose the dialect that matches your database (Standard SQL, MySQL, PostgreSQL, SQLite, MariaDB or SQL Server), whether keywords are uppercased, and a 2 or 4 space indent. It changes layout only and never runs your query or connects to a database. If the formatter cannot parse the statement, the output shows a warning with its message instead. Everything runs in your browser, so your queries stay on your device.

How to use it

  1. Paste your SQL into the input box.
  2. Select the dialect for your database.
  3. Choose uppercase keywords and an indent size.
  4. Copy the formatted query.

Example

Standard SQL, uppercase keywords, 2 space indent.

Input
select id,name from users where age>18 order by name limit 10
Result
SELECT
  id,
  name
FROM
  users
WHERE
  age > 18
ORDER BY
  name
LIMIT
  10

Pick the dialect that matches your database

The formatter has to parse your SQL to lay it out, and each database has syntax the others do not. If you get a parse error, the dialect is the first thing to check.

SQL Server
Square-bracket names such as [id], and TOP, fail under Standard SQL but format under SQL Server. GO batch separators are kept on their own line.
PostgreSQL
Casts like id::text and numbered parameters like $1 need the PostgreSQL dialect.
MySQL and MariaDB
Backtick-quoted names such as `users` are accepted. Choose MySQL or MariaDB for other syntax specific to them.
SQLite
Use it for SQLite files and apps; it follows SQLite's own keyword list.

How the formatted query is laid out

Each clause keyword (SELECT, FROM, WHERE, ORDER BY and so on) goes on its own line, and its contents are indented below it, one column per line. Subqueries in parentheses are indented one level further. Several statements separated by semicolons are split with a blank line between them. Comments are kept where they were.

SELECT
  a
FROM
  t
WHERE
  b IN (
    SELECT
      b
    FROM
      u
    WHERE
      c = 1
  )

Why beautify SQL

Code review
One column and one condition per line makes changes easy to spot in a diff.
Reading generated SQL
Queries copied from an ORM log or a query plan are often one long line. Formatting shows the joins and conditions.
Finding mistakes
A missing JOIN condition or a misplaced AND is easier to see when each part sits on its own line.

Common problems

A warning appears instead of formatted SQL
The statement could not be parsed. Check for unbalanced parentheses or quotes, or choose the dialect you are actually using.
Dialect-specific syntax fails
Pick the matching dialect. For example, SQL Server syntax may not parse under Standard SQL.
Keywords you wanted lowercase are uppercase
Untick Uppercase keywords to keep them as typed.

Frequently asked questions

Does formatting change what my query does?

No. Only whitespace and, if you tick Uppercase keywords, the case of keywords change. Names, values and the order of the query stay the same.

Can I format T-SQL for SQL Server?

Yes. Choose SQL Server in the Dialect list. Standard SQL rejects T-SQL syntax such as square-bracket names.