SQL Utilities

Format, minify, and extract raw SQL queries. Or map live JSON result sets directly into HTML Tables natively.

Input SQL Query

Loading editor...

Formatted Execution

Loading editor...

Got a single-line SQL query that is impossible to read? Paste it here to instantly transform it into a properly indented, keyword-highlighted query that is easy to understand, debug, and share with your team.

Last Updated: April 25, 2025Privacy: 100% Local Browser Processing

What is the Sql?

An SQL Formatter takes raw, compressed, or poorly indented SQL queries and transforms them into clean, readable, properly indented code. It supports SELECT, INSERT, UPDATE, DELETE, and complex JOIN statements, and includes a JSON-to-table converter for visualizing query results. Whether you are writing ad-hoc queries, debugging stored procedures, or preparing documentation, this tool ensures your SQL is readable and consistent.

Real-World Use Cases

  • Debugging complex queriesformat a one-line production query into readable multi-line format to understand its logic and spot potential issues.
  • Documentationformat SQL snippets for inclusion in technical documentation, READMEs, or wiki pages.
  • Code reviewstandardize SQL formatting in pull requests to make diffs cleaner and reviews faster.
  • Learning SQLpaste example queries from tutorials and format them to understand the structure of JOINs, subqueries, and window functions.

How to Use

  1. 1Paste your raw SQL query into the input panel.
  2. 2Click Beautify to format with proper indentation and line breaks.
  3. 3Click Minify to compress into a single line for embedding.
  4. 4Switch to the JSON → Table tab to visualize query results.
  5. 5Paste a JSON array and see it rendered as an HTML table.

Technical Deep Dive

SQL formatting is more nuanced than general code formatting because SQL is a declarative language with context-dependent keywords. The word 'JOIN' means something different depending on whether it follows FROM, a subquery, or a CTE definition. This formatter uses the sql-formatter library, which builds an Abstract Syntax Tree (AST) from the SQL query and then re-serializes it with consistent indentation rules. The AST-based approach ensures that formatting is semantically correct — subqueries are indented relative to their parent clause, JOIN conditions align with their tables, and CASE/WHEN blocks are properly nested. The formatter supports multiple SQL dialects (MySQL, PostgreSQL, SQLite, T-SQL, PL/SQL) because each dialect has unique keywords and syntax that affect parsing. The JSON-to-table converter takes a JSON array of objects (a common format for database query results) and renders it as a clean HTML table with sortable headers, making it easy to visualize and verify query output.

Pro Tips & Best Practices

  • Use the JSON → Table tab to quickly visualize query results without needing a database client. Paste the JSON output from a REST API or database tool.
  • When formatting queries for documentation, use the minified version for inline code and the formatted version for code blocks.
  • The formatter preserves comments in your SQL — both single-line (--) and multi-line (/* */). Use comments to annotate complex queries before sharing.

Frequently Asked Questions