🗄️SQL Formatter
Paste messy SQL and get clean, properly indented queries — free, instant, and runs entirely in your browser.
Formatted SQL will appear here… Free SQL formatter online — beautify queries instantly
Working with a wall of unformatted SQL is hard to read and easy to misjudge. This free SQL formatter takes any query — SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, joins, subqueries — and reformats it into clean, consistently indented SQL with one clause per line and aligned conditions. Paste it in and the formatted version appears instantly, no setup required.
Choose UPPERCASE or lowercase keywords, pick a 2-space, 4-space, or tab indent, and switch to minify mode when you need a compact single-line query instead. Works with MySQL, PostgreSQL, SQLite, SQL Server, and other ANSI-SQL dialects. Everything runs in your browser — nothing is uploaded or stored, so it's safe to paste real queries and schema. No sign-up, no downloads, no limits.
About the SQL Formatter
How formatting works
The formatter tokenizes the query — recognizing keywords, identifiers, strings, numbers, operators, and comments — then rebuilds it clause by clause. Major clauses (SELECT, FROM, WHERE, GROUP BY, ORDER BY, and similar) start on their own line; comma-separated lists like selected columns break one item per line; JOIN ... ON pairs are placed together; and AND/OR conditions in WHERE and HAVING clauses each get their own indented line. Parenthesized subqueries are indented one level deeper than the query that contains them, so nested structure stays easy to follow.
Features
Clause-based indentation
SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY and more each get their own line.
Subquery indentation
Nested SELECTs in parentheses indent one level deeper automatically.
Uppercase / lowercase keywords
Format keywords in UPPERCASE or lowercase without touching identifiers.
Adjustable indent
Choose 2 spaces, 4 spaces, or a tab character.
Minify mode
Collapse the query to a single compact line for configs or environment variables.
Syntax highlighting
Keywords, strings, numbers, and comments are colour-coded for fast scanning.
Handles INSERT, UPDATE, DELETE
Not just SELECT — full DML and CREATE TABLE statements are supported too.
Fully private
No server, no storage — every query stays in your browser.
Formatter, not validator
This tool reformats SQL structure and casing — it does not parse or validate against a specific database's grammar. It won't catch a missing table, a typo in a column name, or a syntax error that a real database engine would reject. For that, run the query against your actual database.
Frequently Asked Questions
What does this SQL formatter do?
Paste any SQL query and it reformats the query into clean, indented SQL — one clause per line, aligned conditions, and consistently cased keywords — so it's easier to read and review.
Which SQL dialects are supported?
The formatter handles standard ANSI SQL syntax used by MySQL, PostgreSQL, SQLite, SQL Server, and similar databases — SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, joins, subqueries, and common clauses. It formats based on general SQL structure rather than validating dialect-specific syntax.
Can I choose uppercase or lowercase keywords?
Yes. Use the Keywords toggle to format SQL keywords like SELECT, FROM, and WHERE in UPPERCASE or lowercase, while leaving your table and column names untouched.
Can I change the indent size?
Yes. Pick 2 spaces, 4 spaces, or a tab character from the Indent dropdown, and the formatted output updates instantly.
Does it handle subqueries and joins?
Yes. Subqueries in parentheses are indented one level deeper than their parent query, and JOIN ... ON clauses are placed on their own lines so the join condition is easy to spot.
What does the Minify button do?
It collapses the formatted SQL into a single compact line with minimal whitespace — useful when you need to paste a query into a config file, environment variable, or anywhere line breaks aren't convenient. Click it again to switch back to Format mode.
Will it validate or fix syntax errors in my SQL?
No. This is a formatter, not a validator — it reformats whitespace and casing based on SQL structure but does not check whether the query is syntactically correct or would execute successfully against a database.
Does it support comments?
Yes. Both single-line comments (-- comment) and block comments (/* comment */) are preserved in the formatted output.
Is my SQL sent to a server?
No. All formatting happens entirely in your browser using JavaScript. Your queries, schema, and any data inside them are never uploaded or stored anywhere.
Is the SQL formatter free to use?
Completely free, with no sign-up, no downloads, and no limits on how much SQL you can format.