SQL Formatter
Format SQL queries for MySQL, PostgreSQL, SQLite, and SQL Server. Capitalizes standard keywords (SELECT, FROM, WHERE) and indents nested subqueries.
Step-by-Step Instructions
Paste Unformatted SQL
Paste messy, minified, or auto-generated ORM SQL queries into the editor.
Select SQL Dialect
Choose Standard SQL, PostgreSQL, MySQL, SQLite, T-SQL (SQL Server), Oracle PL/SQL, or Snowflake.
Configure Formatting Style
Select 2-space or 4-space indentation, keyword casing (UPPERCASE, lowercase), and comma placement (trailing or leading).
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.
Related Utilities
Discover complementary online tools in the same workflow.
JSON Formatter & Validator
Format, beautify, minify, validate, and view JSON data online with instant syntax highlighting and error detection.
Base64 Encoder & Decoder
Encode text or binary data into Base64 format or decode Base64 back into raw string format.
CSV to JSON Converter
Easily convert CSV data to clean JSON format. Turn tabular spreadsheets into structured JSON.
YAML to JSON Converter
Convert YAML configuration files into structured JSON for APIs and modern web tooling.
JWT Parser & Token Debugger
Decode JWT tokens to view header, payload claims, and expiration status without sending secrets anywhere.
Hash Generator (SHA-256, SHA-512, MD5)
Generate cryptographically secure SHA-256, SHA-512, SHA-384, and SHA-1 hashes for any text.