"category": "format-converter",

SQL Formatter

"tldr": Paste messy SQL and get it formatted with consistent indentation and uppercase keywords - readable, review-ready, entirely in your browser.

Turn a one-line query or inconsistently formatted SQL into clean, readable statements: keywords uppercased, one clause per line, JOINs and conditions indented consistently. Handles SELECTs, JOINs, subqueries, CTEs, INSERT/UPDATE/DELETE, and DDL.

{"sql": "formatted sql"}

Readable SQL is not cosmetic - a WHERE clause hidden at the end of a 400-character line is where the wrong-join and missing-condition bugs live. Formatting before a code review or before debugging is the cheapest correctness tool there is. Your queries never leave your browser, so production SQL with table names and literals is safe to paste.

How to format SQL

  1. 1Paste your SQL - single statements or several separated by semicolons.
  2. 2Keywords are uppercased and each clause (SELECT, FROM, WHERE, GROUP BY...) starts its own line.
  3. 3JOIN conditions and boolean logic are indented so the query shape is visible at a glance.
  4. 4Copy the result back into your code, migration, or review.

Convert SQL to Formatted SQL in code

JavaScript (sql-formatter)
import { format } from "sql-formatter"; // npm install sql-formatter

const pretty = format(rawSql, { keywordCase: "upper", tabWidth: 2 });
CI linting (sqlfluff)
pip install sqlfluff
sqlfluff format --dialect postgres queries/*.sql

Frequently asked questions

Which SQL dialects does the formatter understand?

It formats standard SQL, which covers the shared core of PostgreSQL, MySQL, SQLite, and SQL Server. Dialect-specific syntax (e.g. Postgres :: casts, T-SQL brackets) generally passes through untouched; deeply dialect-specific DDL may format imperfectly but is never altered semantically.

Does formatting change what the query does?

No - only whitespace and keyword casing change. Identifiers, literals, and structure are untouched. Note that quoted identifiers keep their exact casing, since "Name" and "name" can be different columns in some databases.

How do I keep SQL formatted automatically in a project?

Use the same library this tool runs on - sql-formatter on npm - in a pre-commit hook, or sqlfluff (Python) for lint + format with dialect awareness in CI. Format-on-save beats format-on-review.

Last updated:

You might also need

Free and in-browser, like everything on JSON Console. Browse all tools →