SQL Formatter
Format SQL queries with proper indentation and keyword highlighting for better readability.
How to use
- 1 Paste your SQL query into the input field.
- 2 The tool formats it with keyword capitalization, consistent indentation, and aligned clauses.
- 3 Review the output — it works with SELECT, INSERT, UPDATE, CREATE TABLE, and JOINs.
- 4 Click Copy to use the formatted query in your IDE or documentation.
Key features
- Capitalizes SQL keywords and aligns clauses for readability
- Supports SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, and JOIN queries
- Handles subqueries and CTEs correctly
- Makes complex queries easy to read and review
SQL Formatting
SQL formatting restructures queries to use consistent indentation, keyword casing, and line breaks — making complex queries significantly easier to read, review, and debug. Raw SQL from an ORM, a query builder, or a logged slow query is often a single long line with no structure whatsoever. Formatted SQL makes the SELECT, JOIN, and WHERE clauses visually distinct.
SQL formatting does not change query behavior. The database engine ignores whitespace — the formatted and unformatted versions produce identical execution plans. The convention for uppercase SQL keywords (SELECT, FROM, WHERE, JOIN) dates to early SQL standards and is still widely followed, though it's a style choice rather than a requirement.
Common Use Cases
Debugging ORM-generated queries
ORMs like Eloquent, Hibernate, and SQLAlchemy produce single-line SQL. Format it to understand exactly what query is being run.
Slow query analysis
Database slow query logs output raw SQL. Format it before feeding it to EXPLAIN to figure out what's causing the performance issue.
Code review of migrations
Format SQL migration scripts before reviewing them in a PR to make the schema changes clearly readable.
Documentation and wikis
Format queries for runbooks, documentation, or internal wikis so colleagues can quickly understand the SQL without deciphering it.
Exploring database dumps
mysqldump and pg_dump produce compact SQL. Format sections of the dump to understand table structures or seed data.
Query construction and testing
Format in-progress queries as you build them to catch missing clauses, wrong join conditions, or misplaced parentheses.
SQL Across Dialects
Formatting syntax is universal, but these dialect differences affect what queries look like.
| Feature | MySQL / MariaDB | PostgreSQL / SQLite |
|---|---|---|
| String quoting | 'string' or "string" | 'string' only |
| Identifier quoting | `column_name` | "column_name" |
| Top N rows | LIMIT n | LIMIT n / FETCH FIRST n ROWS |
| Auto-increment | AUTO_INCREMENT | SERIAL / GENERATED ALWAYS AS IDENTITY |