SQL Formatter
Beautify SQL queries. Format messy SELECT statements into readable code.
What Is a SQL Formatter?
A SQL formatter automatically rewrites SQL queries with consistent indentation, keyword casing, and clause alignment — making complex SQL easy to read, debug, and maintain. SQL formatting matters because queries that are auto-generated by ORMs or hand-written across years of codebase changes accumulate inconsistent styles. A formatter normalises everything so reviewers can focus on logic, not whitespace.
SQL Formatter Online — What This Tool Does
This free SQL formatter beautifies queries entirely in your browser using the sql-formatter library. Supports five dialects (generic SQL, MySQL, PostgreSQL, SQLite, T-SQL), keyword casing options, and indent control. Output matches what tools like DataGrip and DBeaver produce locally — but without needing to install anything.
How to Format SQL Online
- Paste your SQL into the Input pane, or click Upload to load a
.sqlfile. - Select your database dialect: SQL (generic), MySQL, PG (PostgreSQL), SQLite, or T-SQL.
- Pick keyword case — ABC (UPPER), abc (lower), or – (preserve).
- Pick indent: 2, 4, or tab.
- Optional: enable No comments to strip
--and/* */comments before formatting. - Click Format. Output appears in the right pane.
- Click Copy or Download.
Dialect Support
- SQL — Generic ANSI SQL, compatible with most databases.
- MySQL — MySQL and MariaDB-flavored syntax (backticks, ON DUPLICATE KEY UPDATE).
- PG — PostgreSQL with CTEs, window functions, JSONB operators, RETURNING clause.
- SQLite — Lightweight SQLite dialect for mobile and embedded use.
- T-SQL — SQL Server / Azure SQL with
TOP, table hints, variable syntax.
Formatting Options Explained
- Keywords → ABC — converts reserved words to UPPERCASE. SQL standard convention, used by most documentation.
- Keywords → abc — converts reserved words to lowercase. Common in PostgreSQL codebases.
- Keywords → – — preserves original casing.
- Indent — 2 spaces (most common), 4 spaces, or a real tab character.
- No comments — strips
--line comments and/* */block comments before formatting.
Common Use Cases
- Format ORM-generated queries — Hibernate, Doctrine, Sequelize, Prisma produce single-line SQL that's hard to read.
- Code review prep — format before opening a PR so reviewers focus on logic.
- Stored procedure cleanup — legacy stored procs accumulated inconsistent style; a formatter normalises everything.
- Migration scripts — keep migration diffs clean.
- Onboarding — turn unfamiliar SQL into something a new team member can read.
Tips & Tricks
- Pick the right dialect — formatting MySQL with the PostgreSQL preset can mangle backtick identifiers.
- UPPER keywords is the safe default — matches most documentation and books.
- 2-space indent is the dominant standard — pick something else only to match team conventions.
- Always test formatted output — run in your DB client or with
EXPLAINto verify it parses identically. - For embedded SQL use the SQL Minifier instead — produces compact single-line versions.
Related Tools
- SQL Beautifier — same operation, alternate name.
- MySQL Formatter — MySQL-specific dialect.
- PostgreSQL Formatter — PostgreSQL-specific dialect.
- SQL Minifier — opposite operation, compress SQL.
- JSON to SQL — generate INSERT statements from JSON arrays.
Is My SQL Sent to a Server?
No. All formatting runs entirely in your browser using the sql-formatter library. Your SQL — including production credentials, table names, and business logic — never leaves your machine.