SQL Formatter
Format, beautify, and minify SQL queries with customizable indentation.
About this tool
SQL copied from an ORM log, a BI tool or a colleague's chat message usually arrives as one long line. Formatted SQL, with one clause per line and aligned conditions, is far easier to review, debug and keep in version control, and it makes the logic of a query visible: which tables are joined, how they are filtered, and what is grouped.
This formatter understands the syntax of 20 SQL dialects, from PostgreSQL, MySQL and SQL Server to BigQuery, Snowflake, Spark and ClickHouse, so dialect-specific operators and keywords are handled correctly. You control keyword case, indentation and layout. A minify mode does the opposite for embedding queries in code, without touching string literals.
How to use SQL Formatter
- Paste one or more SQL statements, or open a .sql file. The result updates as you type.
- Select your database dialect so that its keywords, operators and quoting rules are recognized.
- Choose the case for keywords, functions and data types, and the indentation (2 spaces, 4 spaces or tabs).
- Pick a layout: Standard indents clauses under their keyword; the tabular styles align keywords in a column, a style many teams use in code review.
- Decide whether AND and OR start or end a line, then copy or download the result. Switch to Minify to compress the query onto one line.
Examples
Format a one-line query
select id, name from users where status = 'active' and created_at >= '2026-01-01' order by name
SELECT id, name FROM users WHERE status = 'active' AND created_at >= '2026-01-01' ORDER BY name
Minify without breaking strings
SELECT * -- all columns FROM t WHERE note = 'a -- b'
SELECT * FROM t WHERE note = 'a -- b'
Comments are removed and whitespace collapsed, but the -- inside the string literal is kept.
A readable SQL style
- Uppercase keywords (SELECT, FROM, WHERE) and lowercase identifiers make the structure of a query stand out. Whatever you choose, be consistent across a codebase.
- Put each selected column and each condition on its own line: diffs in code review then show exactly which column or filter changed.
- Start lines with AND / OR so conditions can be commented out or reordered without editing the previous line.
- Always qualify columns with a table alias when joining (u.id, o.user_id); it prevents ambiguity errors when a new column is added to one table.
- Format before you compare: run two versions of a query through the same settings, then use a text diff to see the real change.
Why the dialect matters
SQL dialects differ in more than functions. PostgreSQL uses :: for casts and $1 for parameters, MySQL quotes identifiers with backticks, SQL Server with square brackets, and BigQuery allows dashes in project names. A formatter that does not know the dialect may split an operator in two or treat a quoted identifier as a string. If formatting fails, check that the right dialect is selected.
Frequently asked questions
Everything you need to know about this tool and data security.
Does formatting change what my query does?
No. Only whitespace, line breaks and the case of keywords, functions and data types change. Identifiers, string literals and the order of everything are preserved.
Why do I get a parse error?
The query is incomplete, contains syntax from a different dialect, or uses template placeholders the dialect does not know (such as {{ var }}). Select the matching dialect, or replace template variables with plain values before formatting.
Can it format stored procedures and multiple statements?
Yes. Several statements separated by semicolons are formatted one after another, and procedural blocks are supported for dialects such as PL/SQL and T-SQL.
Is it safe to paste production queries?
Yes. Formatting happens entirely in your browser; queries are never sent to a server.
Is my data safe when using this tool?
Yes, 100% safe. This tool operates entirely inside your web browser using client-side JavaScript and WebAssembly. Your data never touches any external server.
Related Tools
Prettify, validate, and minify JSON data instantly in your browser.
Convert bidirectionally between JSON and YAML in real time.
Encode text to Base64 or decode Base64 to UTF-8 text with instant live conversion.
Featured Projects tech-fun.net
Explore more AI & productivity tools
Nihongo GameBox
Master Japanese typing, Kana, and JLPT N5–N1 vocabulary through interactive retro arcade games.
ResumeGPT
Tailors CVs and cover letters to every job opportunity with a multi-agent LLM pipeline, job tracking, and scheduled discovery.
CollectMind
Turns your bookmarks into a searchable AI knowledge base — entirely on-device, powered by Chrome's built-in Gemini Nano.