How to format SQL online
- Paste a query or open a
.sqlfile. The formatted version appears on the right as you type. - Choose your database in Dialect so vendor syntax such as
TOP, backticks or::jsonbcasts is recognized. - Pick uppercase or lowercase keywords, 2 spaces, 4 spaces or tabs, and whether
AND/ORstart or end a line. - Copy the result or download it as a
.sqlfile. Minify puts the query on one line for logs, config files or code strings.
What a SQL formatter changes
A formatter rewrites layout, not logic. Each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) starts a new line, selected columns go one per line, joins line up under FROM, and nested subqueries and common table expressions are indented one level deeper. Keywords get a consistent case. Values inside quotes, comments and your table and column names are never altered.
Before
select id,name from users u join orders o on o.user_id=u.id where o.total>100 and u.active=1
After
SELECT id, name FROM users u JOIN orders o ON o.user_id = u.id WHERE o.total > 100 AND u.active = 1
SQL formatting style guide
There is no single official style, but most teams settle on the same handful of rules. Simon Holywell's widely cited SQL Style Guide and the conventions built into this formatter agree on most of them:
- Write reserved words in uppercase and identifiers in lowercase
snake_case. - Put each selected column on its own line so changes show up as one-line diffs in version control.
- Start every clause on a new line and indent what belongs to it.
- Give every derived column and joined table a clear alias with
AS. - Prefer common table expressions (
WITH ... AS) over deeply nested subqueries. - Use explicit
JOIN ... ONinstead of listing tables separated by commas.
Supported SQL dialects
The SQL standard is ISO/IEC 9075 (the current edition is SQL:2023), but every database adds its own syntax. Choosing the right dialect matters most for quoting:
| Dialect | Quoted identifiers | Typical vendor syntax |
|---|---|---|
| MySQL / MariaDB | `name` | LIMIT, GROUP_CONCAT, # comments |
| PostgreSQL | "name" | ::type casts, $$ ... $$ strings, RETURNING |
| SQL Server (T-SQL) | [name] or "name" | TOP (n), @variables, GO |
| Oracle PL/SQL | "NAME" | BEGIN ... END; blocks, :bind variables |
| BigQuery | `project.dataset.table` | STRUCT, ARRAY, QUALIFY |
| Snowflake | "name" | QUALIFY, : path access on VARIANT |
| SQLite | "name", [name], `name` | AUTOINCREMENT, PRAGMA |
How to format SQL in SSMS, VS Code and Notepad++
SQL Server Management Studio gained a built-in formatter in version 22.7 (June 2026, preview), which became generally available in 22.10.2 (September 2026): right-click in the query window and choose Format SQL, or press Ctrl+K, Ctrl+Q, and adjust the style under Tools > Options > SQL Formatter. Older SSMS versions need an add-in such as Redgate SQL Prompt. VS Code has no SQL formatter out of the box; the SQL Formatter VSCode extension uses the same open-source engine as this page, after which Format Document (Shift+Alt+F on Windows, Shift+Option+F on macOS) works on .sql files. Notepad++ has no built-in SQL formatting either, so you need a third-party plugin from Plugins > Plugins Admin, or you can format the query here and paste it back.
When to minify SQL
Minify collapses a query to a single line: whitespace between tokens is reduced to one space, spaces around commas and parentheses are dropped and comments are removed. It is useful for embedding a query in a JSON config, an environment variable or a log line. Text inside quotes is kept exactly, so 'two spaces' stays as it is.
Formatting engine: sql-formatter 15.9.0 (released September 23, 2026), MIT License. Dialect notes checked against the MySQL identifier, PostgreSQL lexical structure and SQL Server database identifier documentation; SSMS versions from the SSMS 22 release notes. Checked October 2026.