Format, beautify, and minify SQL queries instantly. Supports all major SQL dialects.
Our SQL formatter instantly beautifies and formats messy SQL queries into clean, readable code. Whether you're working with MySQL, PostgreSQL, SQL Server, SQLite, or Oracle, this tool handles all standard SQL syntax.
Before formatting:
select u.id,u.name,o.total from users u join orders o on u.id=o.user_id where u.active=1 order by o.total desc
After formatting:
SELECT
u.id,
u.name,
o.total
FROM
users u
JOIN
orders o ON u.id = o.user_id
WHERE
u.active = 1
ORDER BY
o.total DESC
A SQL formatter automatically indents and reformats SQL queries according to consistent style rules. Unformatted SQL — especially complex queries with multiple JOINs, subqueries, and CTEs — is difficult to read and debug. A formatter adds line breaks, indentation, and consistent keyword casing, making queries easier to review, share with teammates, and maintain over time.
Paste your SELECT query into the input area and click Format. The formatter places each clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY) on a new line with consistent indentation. JOIN conditions appear indented under each JOIN. Column lists are aligned for readability. The result is a clean, structured query that is far easier to understand and debug than a single-line string.
This formatter supports standard SQL and is compatible with the major dialects including MySQL, PostgreSQL, SQLite, SQL Server (T-SQL), and Oracle. It handles SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, ALTER TABLE, DROP, and TRUNCATE statements. Dialect-specific functions and syntax (like PostgreSQL's :: cast operator) are preserved without modification during formatting.
SQL beautify (format) adds whitespace, line breaks, and indentation to make queries human-readable. SQL minify does the opposite — it removes all unnecessary whitespace to produce the most compact query string possible. Beautify is used during development and code review; minify is used when embedding queries in configuration files or when query length is constrained. This tool supports both modes.
CTEs use the WITH clause followed by named query blocks. Paste your CTE-based query into the formatter and it will indent each CTE block independently, aligning the AS keyword and formatting the inner SELECT statements. Chained CTEs (multiple WITH blocks) are each formatted on separate lines with clear visual separation, making complex analytical queries much easier to read and maintain.