SQL Formatter & Beautifier: Format SQL Queries Online
Paste a SQL query to get it indented, with uppercase keywords and one clause per line, or minify it. Works with MySQL, PostgreSQL and SQL Server syntax.
Updated November 2026
Reviewed by Rafael Duarte
How to Format SQL Online
From a messy query to readable SQL in seconds
1. Paste your SQL
Any raw, minified, or messy query into the input panel.
2. Configure the style
Indentation, keyword casing, and comma placement (trailing or leading).
3. Format and copy
The result updates automatically as you type. Click Copy (or press Shift+Enter with the focus outside the text box), or download it as formatted.sql.
What this SQL formatter does
Configurable indentation, keyword case, and commas
No dialect to pick
A generic formatter: it recognizes backtick identifiers (MySQL), square brackets (SQL Server), double quotes, and :: casts (PostgreSQL), without per-database rules.
Minify mode
Compresses formatted SQL back into a single line — handy for embedding in config files.
CTEs and window functions
Indents each CTE (WITH) body and subquery, puts every WHEN under its CASE, and keeps OVER (PARTITION BY … ORDER BY …) on one line.
100% in your browser
Your queries — including production schemas — never leave your computer.
What formatting reveals
When you'll reach for this tool
The most common scenarios among people who use a SQL formatter
Code reviews
Readable SQL is reviewable SQL — unformatted queries are nearly impossible to diff meaningfully.
Cleaning up ORM output
SQLAlchemy, Hibernate, and ActiveRecord all generate single-line queries — format them before debugging.
Reading legacy queries
Inherited a 300-line stored procedure with zero formatting? Beautify it to understand it in minutes.
SQL inside config files
Minify formatted queries back to one line to embed in YAML, JSON, or .env files.
Common mistakes
Thinking formatting changes behavior
The database engine ignores whitespace, line breaks, and casing — the query executes identically either way.
Mixing styles across a team
Use the formatter as a shared standard so everyone commits SQL that follows the same convention.
Not indenting subqueries
Nested queries should be indented one level inside their parentheses to stay readable at a glance.
Why use this SQL formatter
Handles complex SQL — CTEs, window functions, CASE expressions, correlated subqueries, and multiple JOINs — indenting every nesting level correctly, not just simple SELECT statements.
There is no dialect to choose: it recognizes the common syntax of MySQL, PostgreSQL, and SQL Server (backticks, brackets, :: casts) and leaves engine-specific constructs untouched — handy for teams that work across more than one database.
Trailing comma vs. leading comma
Two valid conventions — consistency is what actually matters
Frequently asked questions
A SQL formatter takes unstructured or minified SQL and restructures it with consistent indentation, line breaks, and keyword casing so it's easier to read, review, and maintain. It doesn't change what the query does — only how it looks.
No. The database engine ignores whitespace, line breaks, and letter casing when parsing a query, so the formatted version executes identically to the minified one. Formatting is purely cosmetic — it changes readability, not behavior.
No. All formatting runs locally in your browser using JavaScript. Table names, column names, and literal values are never transmitted anywhere, which makes it safe to paste production queries.
There's no dialect selector and no per-database rules — the formatter is generic. It recognizes MySQL backticks, SQL Server brackets, double quotes, and PostgreSQL :: casts, and works well for everyday SQL in those engines, Oracle, and SQLite; very engine-specific syntax passes through untouched but isn't always laid out perfectly. One catch: a backslash inside a single-quoted string is treated as an escape (MySQL style), so in PostgreSQL or standard SQL a literal like 'C:\' can swallow the rest of the query. Check the output when your strings contain backslashes.
With this one, yes: the query is formatted by JavaScript in your browser and nothing is uploaded. Table names, columns and literal values stay on your machine.
There's no file upload. Open the file in any editor, paste its contents into Raw SQL Input, and use the .sql button in the output panel to save the result as formatted.sql.
Yes. The formatter handles CTEs (WITH), window functions (OVER, PARTITION BY), CASE expressions, correlated subqueries, and multiple JOINs, indenting each nested level correctly.
Paste your SQL, switch the mode toggle from Beautify to Minify, and the tool compresses it back into a single line with only the whitespace needed to keep tokens separated. Comments (-- and /* */) are removed. Useful for embedding queries in config files or one-line scripts.
Resources
Related Tools
- CSS Minifier & Beautifier: Minify or Unminify CSS Developer Paste CSS to get the minified version and the bytes saved instantly. It also unminifies CSS back to readable code and keeps your last 20 results locally.
- JSON Formatter & Validator: Fix Errors, Tree View Developer Format, validate and minify JSON with errors shown by line and column, one-click fixes for trailing commas and quotes, and tree or graph views.
- XML Formatter & Validator: Pretty Print, Tree, XPath Developer Paste XML to pretty print or minify it, spot the line with the error, browse it as a tree, run XPath queries, diff two files or convert to JSON.
- Base64 Decode Online — Free Base64 to Text Decoder Developer Free online Base64 decoder — decode Base64 strings back to plain text instantly in your browser. Validates input and shows decoded payload size.
- Base64 Encoder: Encode Text, PDF & Files Online Developer Encode UTF-8 text or any file (PDF, DOCX, XLSX, ZIP up to 50 MB) to Base64 or Base64URL. Runs in your browser, nothing is uploaded. Free, no sign-up.