Format SQL online and transform compressed or hand-written queries into clean, readable statements. This free browser tool adds proper indentation and capitalization to your SQL, making complex joins and subqueries much easier to follow. No signup required, paste your query, format it, and copy it back into your editor or documentation.
The SQL Formatter takes raw, one-line, or poorly formatted SQL queries and outputs clean, consistently indented SQL that is easy to read, understand, and review. Long SQL queries with many joins, subqueries, and conditions become nearly unreadable when compressed or inconsistently formatted. This formatter applies a structured layout: SELECT columns on separate lines, FROM/JOIN/WHERE/GROUP BY/ORDER BY keywords capitalized and on new lines, nested subqueries indented, and long conditions in WHERE clauses placed on individual lines with AND/OR aligned. It supports standard SQL as well as dialect-specific syntax for PostgreSQL, MySQL, Microsoft SQL Server, SQLite, and Oracle. This is useful for database administrators reviewing queries, developers debugging slow queries with EXPLAIN ANALYZE, and engineers preparing SQL for documentation or code reviews.
Well-formatted SQL is much easier to debug and optimize. When a query involves multiple joins, a WHERE clause with several conditions, a GROUP BY, a HAVING, and an ORDER BY, formatting makes the structure immediately clear. This formatter handles common SQL constructs: CTEs (WITH clauses, sometimes called common table expressions), window functions (OVER, PARTITION BY, ORDER BY within OVER), CASE statements, subqueries in SELECT and FROM clauses, and multi-row INSERT statements. Keywords are capitalized by default, which is the most common convention in SQL style guides. Identifiers (table names, column names) preserve their original casing. For PostgreSQL-specific syntax, dollar-quoted string literals ($ ... $), :: type casting, and RETURNING clauses are handled. For MySQL, backtick-quoted identifiers and LIMIT/OFFSET syntax are supported. A common workflow when debugging slow queries is to paste the raw query from application logs into the formatter, read the formatted version to understand its structure, then add EXPLAIN or EXPLAIN ANALYZE before running it in the database console. The formatted version is also easier to paste into documentation, Confluence pages, or Jira tickets where the query needs to be readable by someone not deeply familiar with the codebase.