SQL Formatter

Format and indent SQL queries.

Output appears here.

A complex SQL query generated by an ORM or copied from a slow-query log often arrives as one dense, unreadable line. This tool reformats it with proper indentation, keyword capitalization and line breaks, making the query's actual logic visible.

A query language designed by committee, refined over five decades

SQL's origins trace to IBM's early 1970s research into relational databases, following Edgar F. Codd's influential 1970 paper proposing the relational data model; the language itself, originally called SEQUEL, was developed shortly after by Donald Chamberlin and Raymond Boyce, and was renamed SQL (Structured Query Language) for trademark reasons before being standardized by ANSI in 1986. Despite that formal standardization, SQL as actually written varies considerably in style — different database systems (PostgreSQL, MySQL, SQL Server, and others) support slightly different syntax extensions, and individual teams and tools follow wildly different formatting conventions, which is exactly why a consistent, readable formatting pass is so valuable when working with SQL from an unfamiliar source.

What formatting does

The tool parses your SQL statement's structure — identifying clauses like SELECT, FROM, WHERE, JOIN and GROUP BY — and reformats it with each major clause starting on its own line, consistent indentation for nested subqueries and conditions, and standardized keyword capitalization, all without altering the query's actual logic or the data it will return.

Where formatted SQL is genuinely useful

  • Debugging queries generated by an ORM — object-relational mapping tools (like Hibernate, Sequelize or Django's ORM) often generate SQL as a single dense line, and formatting it is often the essential first step in understanding why a query is slow or returning unexpected results.
  • Reviewing queries in a slow-query log — database performance logs typically capture queries in their raw, unformatted execution form, and readable formatting makes identifying the specific problematic clause (a missing index-friendly WHERE condition, an expensive JOIN) much faster.
  • Code review for database migrations or reports — reviewing a pull request that adds or modifies a SQL query depends on readable formatting to actually evaluate the query's logic and correctness.
  • Learning SQL by studying real queries — properly formatted, clearly structured SQL is significantly easier to learn from than a dense, single-line query pulled from production logs or documentation.

Frequently asked questions

Does formatting SQL change how it executes or what results it returns? No — like other formatting tools on this site, SQL formatting only affects whitespace, line breaks and keyword capitalization; the query's actual logic, and therefore its results, remain completely unchanged.

Why do SQL keywords get capitalized during formatting? A long-standing, widely followed convention (though not a strict requirement, since SQL keywords are typically case-insensitive) that visually distinguishes SQL's reserved keywords from table and column names, making a query's structure easier to scan at a glance.

Does this tool work for any SQL dialect (MySQL, PostgreSQL, etc.)? Standard SQL syntax formats consistently across dialects, though some database-specific extensions or unusual syntax variations may format less predictably, since different database systems have each extended the ANSI SQL standard in their own particular ways over the decades.

Further reading