SQL Formatter
Format, beautify, or minify SQL instantly. Auto-indent, uppercase keywords, break clauses. Works for MySQL, PostgreSQL, SQLite, SQL Server.
What is SQL Formatter?
Format SQL queries - minified, single-line, or auto-generated - into clean, readable code in seconds. Choose 2- or 4-space indentation or tabs, toggle UPPERCASE keywords on or off to match team conventions, and copy the formatted result with one click. A Minify button strips whitespace down to a single line for embedding queries inside code or config. Useful for cleaning up ORM-generated queries before commits, sharing readable joins in Slack code reviews, and embedding nicely formatted SQL examples in technical documentation. Free, with no signup.
How It Works
Using SQL Formatter in 3 Steps
Paste Your Query
Drop any SQL - single-line, minified, or messy auto-generated output. Comments and string literals are preserved.
Pick Your Style
Choose 2 / 4-space indent or tabs, and toggle UPPERCASE keywords on or off to match your team's convention.
Copy or Minify
Copy the formatted result, or use the Minify button to strip whitespace down to a single line - useful for embedding in code.
Use Cases
Who Uses SQL Formatter?
Backend Developers
Clean up auto-generated ORM queries before committing them to Git or pasting into PR descriptions.
Data Analysts & DBAs
Make complex CTEs and joins readable when reviewing a teammate's query in Slack or a spreadsheet.
Documentation Writers
Embed beautifully formatted SQL examples in your docs without a separate VS Code session.
FAQ
SQL Formatter — Frequently Asked Questions
Everything you need to know before you start.
Which SQL dialects does the formatter support?
It works for ANSI-style SQL used by PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, BigQuery, Snowflake, and Redshift. Vendor-specific keywords are kept as-is and won't be reformatted incorrectly.
Does it preserve my comments?
Yes. Both line comments (-- ...) and block comments (/* ... */) are preserved on their own lines in the output.
Will it break complex CTEs and subqueries?
No. Parentheses are tracked and indentation increases for each nested level, so CTEs (WITH ... AS (...)) and subqueries stay readable.
Is my SQL sent to a server?
Never. Formatting happens entirely in your browser using JavaScript - safe for confidential queries containing internal table names or business logic.
More Free Tools
Related Tools
This tool is free. Need something custom built?
These tools are made and kept free by a full-stack developer who ships production web apps, internal tools, AI features, and SEO for founders and teams worldwide. If you need a custom tool, an automation, or a complete website or web app, get a free quote in 24 hours.