SQL Formatter

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

Free Runs in your browser

Converts quoted identifiers (backticks, double quotes, brackets) to the selected dialect. Keywords, functions and string literals are left exactly as written.

How to use

  1. 1 Paste your SQL query into the input field.
  2. 2 The tool breaks the query onto its clauses and indents the conditions, keeping the keywords exactly as you typed them.
  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

  • Breaks queries onto their own clauses and indents the conditions 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 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

The Identifier Quoting selector above converts between backticks, double quotes and square brackets. Everything else in this table (string quoting, top-N syntax, auto-increment) is a language difference the formatter leaves exactly as you wrote it.

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 keeps whatever casing you type and only reorganises the query into lines, so write the keywords the way you want them in the output.

How do I format SQL for MySQL vs PostgreSQL?

The core formatting rules (indentation and line breaks) are the same across all SQL dialects. The one difference this tool handles is identifier quoting: MySQL uses backticks (`table`), PostgreSQL and SQLite use double quotes ("table"), and SQL Server uses square brackets ([table]). Pick your dialect in the Identifier Quoting selector and any quoted identifier gets converted, whichever style you pasted it in. Dialect-specific functions and clauses aren't rewritten; those stay exactly as you typed them.

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 runs entirely client-side, which makes it suitable for working with sensitive queries on offline or air-gapped environments.