SQL Formatter

Format SQL queries with proper indentation and keyword highlighting for better readability.

Free Runs in your browser

How to use

  1. 1 Paste your SQL query into the input field.
  2. 2 The tool formats it with keyword capitalization, consistent indentation, and aligned clauses.
  3. 3 Review the output. It works with SELECT, INSERT, UPDATE, CREATE TABLE, and JOINs.
  4. 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.

FeatureMySQL / MariaDBPostgreSQL / SQLite
String quoting'string' or "string"'string' only
Identifier quoting`column_name`"column_name"
Top N rowsLIMIT nLIMIT n / FETCH FIRST n ROWS
Auto-incrementAUTO_INCREMENTSERIAL / GENERATED ALWAYS AS IDENTITY

Frequently Asked Questions

What is SQL formatting and why is it important?

SQL formatting restructures raw SQL queries by adding consistent indentation, line breaks, and keyword casing. It makes complex queries readable at a glance: you can immediately spot which columns are selected, where joins happen, and what filters apply. This is especially important when debugging ORM-generated queries or reviewing migration scripts in pull requests.

Does SQL formatting change how the query runs?

No. SQL formatting only changes whitespace and casing. The database engine ignores both. The formatted query produces the exact same execution plan as the unformatted version. You can safely format any query without changing its behavior or performance.

What's the difference between uppercase and lowercase SQL keywords?

SQL is case-insensitive, so SELECT and select behave identically. The convention of uppercasing keywords (SELECT, FROM, WHERE, JOIN) dates back to early SQL standards and makes it easier to distinguish keywords from column and table names. It's purely a style choice: this formatter lets you pick whichever you prefer.

How do I format SQL for MySQL vs PostgreSQL?

The core formatting rules (indentation, line breaks, keyword casing) are identical across all SQL dialects. The main differences are in identifier quoting: MySQL uses backticks (`table`) while PostgreSQL uses double quotes ("table"), and in dialect-specific functions. This formatter handles the quoting differences automatically when you select your database dialect.

Can I format SQL without an internet connection?

Yes, this SQL formatter runs entirely in your browser. Your SQL never leaves your machine. The formatting engine is a client-side library that processes everything locally, making it suitable for working with sensitive queries on offline or air-gapped environments.