Free SQL Formatter — Format & Beautify SQL Queries Online
An SQL formatter takes raw or concatenated SQL and returns it with consistent indentation, uppercase keywords, and aligned clauses — making it readable for code review, documentation, and debugging. Supports standard SQL, MySQL, and PostgreSQL syntax in your browser.
developer
Format and beautify SQL queries with consistent indentation and keyword casing.
- Formats SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, and ALTER TABLE statements
- Configurable keyword casing: UPPERCASE, lowercase, or preserve original
- Subquery-aware: nested blocks indented to their own visual level
- JOIN formatting with ON conditions broken to their own line
- SQL minifier mode — collapse to a single line for embedding in code or logs
- Runs entirely in the browser — no SQL is uploaded or stored
- Adjustable indent size (2 or 4 spaces) to match team style guides
Everything you need in one SQL Formatter
SQL beautifier
Turns a single-line query into readable SQL with each clause — SELECT, FROM, WHERE, JOIN, GROUP BY — on its own line and columns aligned underneath.
Keyword casing control
Uppercase keywords for the classic SQL look, lowercase them for a modern style, or preserve the original casing — applied consistently across the entire query.
Subquery & join aware
Nested subqueries are indented into their own block, joins break onto new lines with their ON conditions, and CREATE TABLE column lists are aligned.
SQL minifier
Collapse a formatted query back to a single line for embedding in application code, logs, or migration scripts — without changing what the query does.
How to use SQL Formatter
Paste your SQL
Paste any raw or minified SQL query — SELECT, INSERT, UPDATE, DELETE, CREATE TABLE.
Choose dialect
Select MySQL, PostgreSQL, or standard SQL. Toggle keyword uppercasing and indent size.
Copy output
The formatted SQL appears instantly. Copy to clipboard for your editor or documentation.
SQL SELECT clause order
| Clause | Purpose |
|---|---|
| SELECT | Columns and expressions to return |
| FROM | Source tables, with table aliases |
| JOIN … ON | Combine rows from related tables |
| WHERE | Filter rows before grouping |
| GROUP BY | Collapse rows into aggregate groups |
| HAVING | Filter groups after aggregation |
| ORDER BY | Sort the final result set |
| LIMIT / OFFSET | Restrict how many rows are returned |
How to fix common syntax errors
Most “invalid JSON” failures come from a small set of mistakes. Paste the failing JSON above, click Validate, and the tool points you at the exact line and column.
SELECT id FROM (SELECT id FROM usersCount opening and closing parentheses — the formatter highlights the mismatch. Add the missing closing paren before the outer query's semicolon.
SELECT "name" FROM users WHERE status = "active"In SQL, double quotes denote identifiers (column/table names), not string literals. Use single quotes for string values: WHERE status = 'active'.
SELECT `user_id` FROM `orders`Backticks are MySQL-only. In PostgreSQL, use double-quoted identifiers (`"user_id"`) or unquoted names. Run a global replace before migrating queries across dialects.
SELECT id
, name
, emailSQL does not allow a leading comma before the first column. Use trailing commas (comma at the end of each line except the last) — this is ANSI-valid and produces cleaner diffs.
SELECT COUNT(*) AS count FROM ordersCOUNT, ORDER, GROUP, and similar reserved words cause parse errors as bare aliases in strict engines. Quote the alias: AS "count" (PostgreSQL) or AS `count` (MySQL).
SELECT 1
SELECT 2Most SQL engines require a semicolon to terminate each statement in a multi-statement script. Add a semicolon after each statement — the formatter will preserve it in the output.
Frequently asked questions
Standard ANSI SQL, MySQL 5.7+, MySQL 8+, and PostgreSQL 14+ are all supported. All common DML statements (SELECT, INSERT, UPDATE, DELETE, MERGE) and DDL (CREATE TABLE, ALTER TABLE, DROP, CREATE INDEX) are formatted. Dialect-specific syntax — MySQL's backtick identifiers, PostgreSQL's `::` cast syntax, and dialect-specific functions — is preserved without modification.
You might also need
JSON Formatter & Validator
Format, validate, and minify JSON instantly in your browser.
Regex Tester
Test regular expressions against strings with live match highlighting.
Cron Expression Builder
Build cron schedules visually and get the expression + plain-English explanation.
.env File Generator
Generate a boilerplate .env file for Laravel, Next.js, Node.js, or Docker.
.htaccess Generator
Generate Apache .htaccess rules for redirects, HTTPS, caching, and security headers.
JWT Decoder
Decode and inspect JSON Web Token header, payload, and signature.
Base64 Encoder / Decoder
Encode and decode Base64 strings instantly in your browser.
Color Contrast Checker (WCAG)
Check foreground/background color contrast for WCAG AA and AAA compliance.
Further reading
Authority documentation and specifications behind this tool.
Need this built into your product?
We design and build custom software — SaaS platforms, MVPs, AI agents, and web apps.
Custom SaaS Development
End-to-end SaaS — API, auth, billing, dashboard, deployment.
MVP Development
Working product in 6–8 weeks. Fixed price, committed timeline.
AI Agent Development
Custom AI agents and workflow automation for your stack.
Web App Development
Full-stack web apps built with modern frameworks and best practices.
Have a project in mind?
We turn ideas into production-ready software — SaaS, web apps, mobile, and AI agents. Fixed price. Committed timeline. No surprises.