SQL Formatter

Paste messy SQL and get it back formatted, readable, and syntax-highlighted. Supports all major dialects.

💾 Format SQL

Dialect:
Keywords:
Indent:
Input
Output

Why Format SQL?

Raw or minified SQL is difficult to read, especially when queries span multiple tables with JOINs, subqueries, and complex WHERE clauses. Formatted SQL places each clause on its own line with consistent indentation, making it easier to understand the query structure, spot errors, and collaborate with other developers during code reviews.

Well-formatted SQL is also essential for documentation and debugging. When a query returns unexpected results, clean formatting lets you trace the logic step by step — from the tables being joined, to the conditions being filtered, to the columns being selected.

SQL Formatting Best Practices

One clause per line: Place SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, and LIMIT on separate lines. This makes the query scannable at a glance.
Indent column lists: Each selected column on its own indented line improves readability when selecting many columns.
Uppercase keywords: Using UPPERCASE for SQL keywords and lowercase for table/column names creates a clear visual distinction.
Align conditions: Place AND and OR at the start of new indented lines within WHERE clauses so conditions are easy to scan.

Frequently Asked Questions

What is SQL formatting?
SQL formatting adds indentation, line breaks, and consistent capitalization to queries, making them easier to read, review, and debug.
Does this work with MySQL and PostgreSQL?
Yes. This tool formats standard SQL syntax compatible with MySQL, PostgreSQL, SQL Server, SQLite, and other databases. Select your dialect from the dropdown.
How do I minify SQL?
Click the Minify button to collapse SQL to a single line, strip comments, and normalize whitespace. Useful for embedding in code or reducing query string length.
What is SQL indentation?
SQL indentation uses spaces to visually nest sub-clauses. Column lists, WHERE conditions, and subqueries are indented to show their hierarchical relationship.
Is my SQL sent to a server?
No. Everything runs in your browser. Your SQL never leaves your computer.