deftools.io Developer Tools

SQL Formatter

Format, beautify, and minify SQL queries. Dialect-aware keyword handling for MySQL, PostgreSQL, SQLite, and Standard SQL.

About this tool

A SQL formatter that takes a minified or messy query and re-indents it into readable, consistently styled SQL. It recognizes keywords (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, …), aligns subqueries, and uppercases keywords on request. Pick a dialect — MySQL, PostgreSQL, SQLite, or Standard SQL — to handle dialect-specific keywords like ILIKE (PostgreSQL), AUTO_INCREMENT (MySQL), or VACUUM (SQLite).

Example: select u.id,count(o.id) as c from users u left join orders o on o.user_id=u.id where u.active=1 group by u.id having c>5 order by c desc becomes a multi-line query with each clause on its own line and the join condition indented underneath the join.

Handy for pasting a query copied out of a slow-log, ORM debug output, or a teammate's Slack message before reading or editing it. Choose between 2-space, 4-space, or tab indentation. Use the Minify button to compress everything back to a single compact line for embedding in code or logs.

FAQ

Which SQL dialects are supported?

The dialect selector adjusts the keyword list per database: Standard SQL (ANSI), MySQL, PostgreSQL, and SQLite. The formatter does not parse dialect-specific syntax deeply, so unusual constructs (e.g. PostgreSQL dollar-quoted strings) are passed through unchanged.

Does it execute or validate the query?

No. It only reformats the text — it never runs the SQL or checks whether it is syntactically valid for any specific database.

What does Minify do?

It collapses the formatted SQL back to a single line by removing all newlines and extra whitespace. Useful when you need a compact one-liner for embedding in application code, config files, or logs.

Will it uppercase my keywords?

Only if "Uppercase keywords" is checked (it is on by default). Uncheck it to keep identifiers and keywords in their original casing.

Can this format GraphQL queries?

No. This tool formats SQL (Structured Query Language) for relational databases. For formatting GraphQL queries, mutations, fragments, and schemas, use the dedicated <a href="/graphql-formatter">GraphQL Formatter</a>.

More developer tools

Copied!