SQL Formatter automatically formats and indents SQL queries for readability. Paste any SQL statement β SELECT, INSERT, UPDATE, DELETE, CREATE, or stored procedures β and the formatter applies consistent indentation, keyword capitalization, and line breaks. It supports standard SQL, PostgreSQL, MySQL, SQLite, Oracle, and T-SQL (Microsoft SQL Server) dialects.
Unformatted SQL is hard to review, debug, and maintain. A single-line query with JOINs, subqueries, and WHERE clauses is nearly impossible to read when generated by an ORM or legacy code. Well-formatted SQL aligns JOIN conditions, indents subqueries, and places each clause on its own line β making logic errors visible at a glance.
The formatter handles complex constructs: CTEs (WITH clauses), window functions (OVER, PARTITION BY, ORDER BY), CASE expressions, correlated subqueries, and multi-table JOINs. Keyword casing options include UPPERCASE (most common), lowercase, and title case. The tool is useful for code reviews, adding queries to documentation, and cleaning up generated SQL before committing it to source control.
Unformatted SELECT with JOINs
Result: SELECT u.name,o.total,p.name FROM users u JOIN orders o ON u.id=o.user_id JOIN products p ON o.product_id=p.id WHERE u.active=1 β formatted with each JOIN on its own line, indented ON conditions, and SELECT list on separate lines
CTE formatting
Result: WITH monthly_totals AS (SELECT DATE_TRUNC('month', created_at) AS month, SUM(amount) AS total FROM orders GROUP BY 1) SELECT * FROM monthly_totals β properly indented CTE block with the outer query separated
CASE expression formatting
Result: CASE WHEN status='active' THEN 'Active' WHEN status='pending' THEN 'Pending' ELSE 'Other' END β each WHEN/THEN on its own line, ELSE and END aligned
Does formatting change the query behavior?
No. SQL formatting is purely cosmetic β whitespace has no effect on SQL semantics. The formatted query produces identical results to the original. Formatting changes only indentation, line breaks, and optionally keyword case.
What is a CTE and how does the formatter handle it?
A CTE (Common Table Expression) is defined with the WITH keyword before the main query. The formatter indents the CTE body and separates multiple CTEs. CTEs improve readability for recursive queries and complex multi-step logic.
What is the difference between SQL dialects?
Standard SQL is the ANSI specification. Each database vendor adds extensions: PostgreSQL has RETURNING, dollar-quoted strings, and jsonb operators; MySQL has LIMIT syntax differences; T-SQL (SQL Server) uses TOP instead of LIMIT and supports table hints; Oracle uses ROWNUM. Select your dialect for syntax highlighting and formatting rules specific to your database.
Should I commit formatted SQL to version control?
Yes β consistently formatted SQL is easier to review in PRs. The key is team consistency: agree on a formatting style, use the same formatter settings, and consider adding an automated SQL formatter check to your CI pipeline.
How do I format SQL inside application code?
Extract the SQL string to a .sql file for formatting, then paste it back. Avoid reformatting SQL that is generated at runtime β format only literal SQL strings in your codebase.