Format and beautify SQL queries with syntax highlighting. Supports 6 dialects — Standard SQL, MySQL, PostgreSQL, T-SQL, PL/SQL, and SQLite.
SELECT u.id, u.name, u.email, count(o.id) AS order_count, sum(o.total) AS total_spent FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.created_at >= '2026-01-01' AND u.status = 'active' GROUP BY u.id, u.name, u.email HAVING count(o.id) > 0 ORDER BY total_spent DESC LIMIT 10;
This tool runs 100% in your browser. All computation happens locally on your device — your input is never uploaded to any server. Results are for reference only.
A formatter is a small compiler pipeline with two stages. The lexer reads the raw query and classifies each run of characters as a keyword, identifier, string literal, number, or operator — the same tokens a database parser would see. The printer then re-emits that token stream: it converts keywords to the chosen case (UPPERCASE, lowercase, or preserve), puts each major clause — SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY — on its own line, indents nested expressions by 2 spaces (or a tab), and always leaves string literals byte-for-byte intact. That last rule is what makes compress mode safe: newlines are stripped outside literals, so a multi-line string inside a query survives minification. Dialect support (MySQL backticks, T-SQL brackets, Postgres dollar quotes) tunes both stages.
Formatting never changes what the query means — it only changes how the token stream is laid out.
Ken maintains an analytics dashboard and pastes a minified SQL query his colleague copied straight out of the database console.
To format SQL: paste your query — the tool adds proper indentation, capitalizes keywords, and aligns clauses for readability. Supports MySQL, PostgreSQL, SQLite, and SQL Server.
FreeToolHub SQL Formatter is a free browser-based tool that beautifies and validates SQL queries, no signup, no upload.
Format and beautify SQL queries with syntax highlighting. MySQL, PostgreSQL, T-SQL. Compress mode for production. Free, no signup.
This formatter beautifies SQL queries: it parses the statement, applies consistent indentation and casing to keywords, breaks long clauses onto readable lines, and adds syntax highlighting so structure jumps out. It handles standard SQL plus the dialects that matter daily — MySQL, PostgreSQL, and T-SQL — and includes a compress mode that strips whitespace for shipping queries through APIs or embedding them in code where size counts. Formatting runs entirely in your browser; queries never touch a server, which matters for anything touching production data.
Analysts inheriting thousand-character single-line queries pasted from logs or BI tools who need them readable before editing. Developers reviewing queries in code review where formatting noise drowns out the logic changes. DBAs documenting saved queries and views with consistent style. Data engineers moving queries between dialects who want dialect-appropriate keyword handling. Anyone pasting SQL into tickets, docs, or Slack where a wall of text loses the reader.
(1) Paste your query — single statement or a batch. (2) Pick the dialect: standard SQL, MySQL, PostgreSQL, or T-SQL, so keywords and functions format per that flavor. (3) The formatter indents nested subqueries and JOIN clauses onto their own lines, uppercases keywords, and aligns column lists; adjust indent width if your team's style differs. (4) Use compress mode to minify instead when you need the query compact. (5) Copy the result; formatting is semantics-preserving, so the output runs identically.
Unformatted SQL is where bugs hide. A WHERE clause jammed onto one line makes a missing AND invisible; aligned ON conditions make wrong join keys obvious at a glance; consistent keyword casing lets the eye separate structure from data instantly. The conventions that have converged across teams: keywords uppercase and on their own lines for major clauses (SELECT, FROM, WHERE, GROUP BY, ORDER BY); one column per line in SELECT lists for long queries, with a trailing comma convention your team picks once; JOINs with their ON condition indented under the join; subqueries indented one level and given a blank line above. Beyond readability, formatting is a collaboration contract: code review on consistently formatted queries reviews logic instead of arguing whitespace, and diffs on formatted queries show actual changes rather than reflow noise. The dialect choice matters more than people expect — T-SQL and PostgreSQL treat certain functions and identifiers differently — so format with the dialect you run, and when shipping queries through APIs or embedding them in application code, compress mode strips the whitespace back out.
Because the same query can be written differently per engine: PostgreSQL uses LIMIT while SQL Server uses TOP, MySQL quotes identifiers with backticks while PostgreSQL uses double quotes, and PL/SQL packages add blocks that standard SQL never has. Formatting with the wrong dialect risks reflowing around syntax the engine does not accept. Pick the dialect first — the formatter adjusts keyword handling to match.
UPPERCASE keywords are a legacy convention from punch-card-era mainframe dumps and remain the most common house style in corporate SQL; lowercase wins in newer teams and in query builders that syntax-highlight anyway. Either is fine — consistency within a codebase beats any external rule. The formatter switches casing in one click so you can match the file you are editing, not fight it.
No — parsing and formatting run entirely in JavaScript in your page, and nothing is uploaded. This matters more than it sounds: real queries embed table names, column names, and WHERE values that describe your business. Pasting them into a random website is a data leak waiting for a log file; here the round trip never leaves the tab.
Leading commas put the comma at the start of each column line (`, col2` instead of `col1,`) so that adding or removing a line never touches its neighbor — cleaner diffs in code review and fewer missing-comma errors when editing long SELECT lists. Trailing style reads more naturally to most people. The formatter supports both; pick whatever your team's existing code does.
Standard SQL (ANSI), MySQL, PostgreSQL, and T-SQL (SQL Server). It handles complex queries including JOINs, subqueries, CTEs (WITH clauses), window functions, and UNION/INTERSECT/EXCEPT. The formatter applies consistent indentation, keyword capitalization (SELECT/FROM/WHERE), and aligns column lists for readability. A compression mode minifies whitespace for production queries.
Yes. The parser tokenizes SQL to distinguish string literals (single quotes), line comments (--), block comments (/* */), and identifiers from keywords. Comments and string contents are preserved exactly as-is. This prevents the formatter from breaking inline SQL hints or altering string values during formatting.
Why did the cow cross the road?
No signups, no data sold. The core of every tool is free forever — the optional Pro plan adds batch processing, unlimited downloads, white-label exports and an ad-free experience.
☕Support me on Ko-fi— keep tools free100% of proceeds go towards hosting & building more free tools.