|
Developer Utilities 100% Client-Side · 0 Bytes Sent to Server Instant In-Memory Execution

SQL Formatter

Format SQL queries for MySQL, PostgreSQL, SQLite, and SQL Server. Capitalizes standard keywords (SELECT, FROM, WHERE) and indents nested subqueries.

SQL Query Minifier & Comment StripperSaved 22% (89 chars removed)
Raw SQL Query411 chars
Minified Query

Step-by-Step Instructions

1

Paste Unformatted SQL

Paste messy, minified, or auto-generated ORM SQL queries into the editor.

2

Select SQL Dialect

Choose Standard SQL, PostgreSQL, MySQL, SQLite, T-SQL (SQL Server), Oracle PL/SQL, or Snowflake.

3

Configure Formatting Style

Select 2-space or 4-space indentation, keyword casing (UPPERCASE, lowercase), and comma placement (trailing or leading).

4

Copy Formatted SQL

Copy clean, readable SQL query code with proper indentation across SELECT, FROM, JOIN, and WHERE clauses.

Key Features & Capabilities

  • Multi-dialect SQL formatter: PostgreSQL, MySQL, SQLite, Microsoft SQL Server (T-SQL), Oracle, MariaDB, BigQuery
  • Keyword casing customizer (UPPERCASE, lowercase, or TitleCase for `SELECT`, `FROM`, `WHERE`, `JOIN`, `GROUP BY`)
  • Configurable comma placement (standard trailing commas or leading commas for easy line commenting)
  • Subquery and CTE (`WITH` clause) intelligent recursive indentation

Frequently Asked Questions

Why format SQL keywords in UPPERCASE?

Formatting SQL keywords (`SELECT`, `FROM`, `WHERE`, `INNER JOIN`, `GROUP BY`) in UPPERCASE while keeping table and column names in lowercase or snake_case is the universal industry standard. It creates instant visual separation between the query logic and database schema identifiers, dramatically improving readability.

How does the formatter handle complex subqueries and Common Table Expressions (CTEs)?

The formatter uses AST-based parsing to recursively indent nested subqueries (`(SELECT ...)`), CTEs (`WITH regional_sales AS (...)`), and window functions, maintaining clear visual hierarchy across multi-table joins.

What is leading comma vs trailing comma formatting in SQL?

**Trailing commas** place the comma at the end of each column line (standard). **Leading commas** place the comma at the beginning of each line (` , price`). Leading commas are popular in data engineering because you can comment out any single column line without causing a trailing comma syntax error.

Can this formatter format ORM-generated SQL queries (Prisma, Hibernate, Drizzle)?

Yes. ORM-generated queries often output as single unreadable lines spanning thousands of characters. Our formatter breaks them into properly structured, indented clauses for rapid query debugging and performance tuning.

Discover complementary online tools in the same workflow.