Tools
SQL Formatter
The SQL formatter takes raw or minified SQL queries and produces consistently indented, readable output with proper keyword casing. It supports multiple SQL dialects including MySQL, PostgreSQL, SQLite, and T-SQL, and allows you to configure indentation width and whether keywords should be uppercase or lowercase. It is an essential tool for reviewing queries, writing documentation, and cleaning up generated SQL.
What is the SQL Formatter?
The SQL formatter is a browser-based tool that parses SQL statements and reformats them according to consistent style rules. It handles complex constructs including subqueries, CTEs (WITH clauses), window functions, JOIN conditions, and multi-value INSERT statements. The formatter separates clauses onto their own lines, aligns JOIN conditions, and indents nested subqueries. This makes even highly complex queries readable without a database IDE.
How does it work?
Paste your SQL query into the input area, select the target dialect and formatting options, and click Format. The tool tokenizes the SQL, parses the clause structure, and reconstructs the query with standardized whitespace. Keyword casing (SELECT vs select), indentation depth, and comma placement (leading vs trailing) can be configured. The formatted output is syntax-highlighted for readability and can be copied with one click.
Typical Use Cases
- Cleaning up auto-generated ORM queries for manual review
- Formatting queries before committing them to version control
- Preparing readable SQL examples for technical documentation
- Debugging complex multi-join queries by imposing a clear structure
Step-by-step Guide
- Step 1: Paste your SQL query into the input area.
- Step 2: Select the SQL dialect (MySQL, PostgreSQL, T-SQL, SQLite).
- Step 3: Configure indentation and keyword casing preferences.
- Step 4: Click Format and copy the result.
Example
Input
select u.id,u.name,o.total from users u inner join orders o on u.id=o.user_id where o.total>100
Output
SELECT u.id, u.name, o.total FROM users u INNER JOIN orders o ON u.id = o.user_id WHERE o.total > 100
Tips & Notes
- Uppercase SQL keywords (SELECT, FROM, WHERE) improve readability and are the de facto standard in most style guides.
- Format your SQL before code review to reduce noise from whitespace differences in diffs.
- Use CTEs (WITH clauses) instead of deeply nested subqueries — they are easier to format and understand.
Frequently Asked Questions
Does the formatter change the meaning of my query?
No. The formatter only changes whitespace and optionally keyword casing. It does not reorder clauses, add or remove conditions, or alter any SQL logic.
What if my query contains dialect-specific syntax the formatter does not recognize?
The formatter may not parse proprietary or very new SQL extensions. In those cases, it will typically format as much as it can and leave unrecognized tokens as-is. Always test formatted queries before running them.
SQL Formatter
Format and prettify SQL queries with syntax highlighting, line numbers, and support for Standard SQL, MySQL, PostgreSQL, T-SQL, and SQLite.
Open Tool