Skip to content
Devtoolry

SQL Formatter

Format and beautify SQL queries online for MySQL, PostgreSQL, SQLite, SQL Server and more, with keyword casing and indentation options. Runs in your browser.

Runs in your browser · Nothing uploadedFree · No sign-up

Something not working, or missing a feature? Send feedback

About the SQL Formatter

Long SQL queries are much easier to debug when each clause starts on its own line. The SQL Formatter indents queries for the dialect you use and can upper- or lower-case keywords.

Everything runs in your browser, so your input is never uploaded to a server.

How to use the SQL Formatter

  1. Paste one or more SQL statements.
  2. Select your dialect (MySQL, PostgreSQL, SQLite, SQL Server and others) and keyword casing.
  3. Copy or download the formatted SQL.

Example

Format a one-line MySQL query

Input

select u.id, u.email, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.id, u.email order by orders desc limit 10

Result

SELECT
  u.id,
  u.email,
  count(o.id) AS orders
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  u.active = 1
GROUP BY
  u.id,
  u.email
ORDER BY
  orders DESC
LIMIT
  10

Dialect MySQL, keywords in UPPERCASE, 2-space indentation. Function names such as count keep their original case.

Common mistakes

  • Wrong dialect. Backtick identifiers (MySQL), square brackets (SQL Server) and :: casts (PostgreSQL) only parse in their own dialect. Pick yours before formatting.
  • Template placeholders. Placeholders such as ${table} from application code are not SQL. Replace them with sample values or ? parameters first.
  • Formatting does not check tables. A nicely formatted query can still reference a column that does not exist. Run it against your database to validate it.

Works well with the SQL Formatter

Frequently asked questions

Why choose a dialect?

Dialects differ in syntax such as quoting, operators and functions. Choosing the right one makes the formatter parse those correctly.

Does it validate my query?

It needs to tokenise the SQL, so badly broken queries are reported, but it does not check table or column names against a database.

Can it format several statements at once?

Yes. Separate statements with semicolons and each one is formatted in turn.

Does it change what my query does?

No. Only whitespace, line breaks and keyword case change; identifiers, values and the order of clauses are kept.

Guides and tutorials