VSCode SQL Formatter — The Complete Setup Guide
Published: July 8, 2026 | Updated: September 29, 2026
If you write SQL in Visual Studio Code, you have probably looked for a VSCode SQL formatter to keep your queries clean and readable. Unlike SSMS, VS Code does not ship with a built-in SQL formatter — but the extension ecosystem fills the gap beautifully.
This guide compares the best VS Code SQL formatting extensions, shows you how to configure each one, and walks through setting up format-on-save so your SQL files stay clean automatically. When you need a quick fix without leaving the browser, use our free online SQL formatter.
Table of Contents
- Why You Need a SQL Formatter in VS Code
- SQL Formatter (adpyke) — The Top Choice
- Every settings.json Option, Explained
- Prettier + prettier-plugin-sql
- When Prettier, ESLint, and the SQL Extension Fight
- SQLFluff — For Teams and CI Pipelines
- How to Enable Format-on-Save for SQL
- Formatting SQL in Jupyter Notebooks
- Multi-Dialect Workspaces and Team-Shared Settings
- Using an Online SQL Formatter
- FAQ — Format SQL in VS Code
1. Why You Need a SQL Formatter in VS Code
Formatted SQL is easier to read, debug, and maintain. When you write SQL queries manually, indentation drifts, keywords get mixed case, and complex clauses become hard to follow. A good VSCode SQL formatter gives you:
- Consistent keyword casing — All keywords uppercase, identifiers lowercase (or your preferred style)
- Proper indentation — Subqueries, JOINs, and WHERE clauses align correctly
- Readable line breaks — Each major clause on its own line
- Team consistency — Everyone on the team uses the same formatting rules
VS Code alone cannot do this. You must install a formatting extension. The three best options are covered below.
2. SQL Formatter (adpyke) — The Top Choice
The SQL Formatter extension by adpyke is the most popular VS Code SQL formatter on the marketplace, with millions of installs. It uses the sql-formatter library under the hood — the same engine that powers many online formatters.
Installation
- Open VS Code
- Go to the Extensions view (Ctrl+Shift+X)
- Search for "SQL Formatter" by adpyke
- Click Install
Or install via the command line: code --install-extension adpyke.vscode-sql-formatter
Dialect Support
This extension supports 15+ SQL dialects: MySQL, PostgreSQL, SQLite, BigQuery, DB2, Hive, MariaDB, PL/SQL, Redshift, SingleStoreDB, Snowflake, Spark SQL, T-SQL (SQL Server), Trino, and Standard SQL. You can set a default dialect in VS Code settings.
Configuration
In your VS Code settings.json, you can customize:
{
"sql-formatter.uppercase": true,
"sql-formatter.linesBetweenQueries": 2,
"sql-formatter.tabWidth": 2,
"sql-formatter.dialect": "postgresql"
}
These settings control keyword casing, spacing between queries, and the default dialect. The extension picks them up immediately without reloading.
Pro tip: Pair this extension with SQLFormat.io for quick online formatting when you are reviewing or sharing SQL outside VS Code. Both use the same formatting engine, so the output matches.
3. Every settings.json Option, Explained
Which setting names you actually have depends on which build of the extension you installed. The original adpyke extension (v1.4.4, last published 2019) exposes only three keys: sql-formatter.dialect, sql-formatter.uppercase, and sql-formatter.linesBetweenQueries. It wraps an old fork of the library and predates almost every formatting option that exists today.
The maintained successor is SQL Formatter VSCode by Rene Saarsoo (ReneSaarsoo.sql-formatter-vsc) — the official VS Code extension of the sql-formatter library itself. It exposes the full option set under the SQL-Formatter-VSCode. namespace. Everything below refers to that build; if you are still on the 2019 extension, the only thing you can tune is the dialect, keyword casing, and query spacing.
dialect
Default auto-detect, and the one option you should never leave at its default value. Auto-detection relies on the language ID VS Code assigned to the file, which only works if you have a dialect-specific extension installed that registers its own language. When detection fails, the formatter falls back to generic sql — a lowest-common-denominator grammar that parses basic statements and nothing else.
The enum covers bigquery, db2, db2i, duckdb, hive, mariadb, mysql, n1ql, plsql, postgresql, redshift, singlestoredb, snowflake, spark, sqlite, tidb, trino, transactsql, and sql. The difference is not cosmetic: SELECT TOP 10 only parses under transactsql, LIMIT belongs to the MySQL and PostgreSQL grammars, and Snowflake's :: casts and QUALIFY clause will confuse most other dialects.
keywordCase, dataTypeCase, functionCase, identifierCase
All four take preserve, upper, or lower, and all four default to preserve — meaning the formatter keeps whatever casing you typed. That default is why so many teams think their formatter "does not work": the indentation changes but a file touched by three people still has three different casing styles. Set keywordCase to upper to get the standard look. Leave identifierCase alone: it is flagged experimental and rewrites the casing of your column and table names, which will break queries against case-sensitive quoted identifiers in PostgreSQL.
indentStyle
standard (default), tabularLeft, or tabularRight. Standard puts each clause and each JOIN on its own line. The tabular styles keep a central column of keywords aligned — the style you see in old sql-formatter output and in some Oracle shops. Most teams want standard; switch only if you are matching an existing house style.
ignoreTabSettings, tabSizeOverride, insertSpacesOverride
By default the extension honours VS Code's own editor.tabSize and editor.insertSpaces, so your SQL indent follows your general editor preference. Set ignoreTabSettings to true and the formatter reads tabSizeOverride and insertSpacesOverride instead. Use this when a repo must produce two-space SQL indent regardless of what each developer's editor is configured to do.
logicalOperatorNewline
before (default) or after. This controls whether a long boolean expression breaks the line before AND and OR or after it. Breaking before the operator is what almost everyone expects when scanning a WHERE clause, because the operator starts the line and lines up with its siblings.
expressionWidth
Default 50. The maximum number of characters allowed in a parenthesised expression before the formatter splits it across lines. This is what makes long IN (...) lists explode into one value per line. Raising it to 80 or 120 keeps those lists compact. Note that this is its own setting — Prettier's printWidth does not influence it, even when Prettier owns the file.
linesBetweenQueries
Default 1 — the number of blank lines inserted between statements in the same file. Bump it to 2 for migration files and script dumps, where visual separation between statements matters more than density.
denseOperators and newlineBeforeSemicolon
denseOperators (default false) strips the spaces around operators, turning a = 1 into a=1. newlineBeforeSemicolon (default false) puts the terminating semicolon on its own line instead of at the end of the last statement line. Both are cosmetic; pick whichever your reviewer will not argue about.
paramTypes
Controls which placeholder syntaxes the formatter recognises as parameters: ?, $1, :name, @name, ${name}, and the various dialect-specific forms. This matters more than it sounds. With the wrong setting, a named parameter like :user_id is tokenised as a plain identifier and spacing around it drifts. If your application uses named or numbered parameters, declare the type explicitly.
A configuration worth copying
{
"SQL-Formatter-VSCode.dialect": "postgresql",
"SQL-Formatter-VSCode.keywordCase": "upper",
"SQL-Formatter-VSCode.dataTypeCase": "upper",
"SQL-Formatter-VSCode.functionCase": "preserve",
"SQL-Formatter-VSCode.indentStyle": "standard",
"SQL-Formatter-VSCode.logicalOperatorNewline": "before",
"SQL-Formatter-VSCode.expressionWidth": 80,
"SQL-Formatter-VSCode.linesBetweenQueries": 2,
"SQL-Formatter-VSCode.ignoreTabSettings": true,
"SQL-Formatter-VSCode.tabSizeOverride": 2,
"SQL-Formatter-VSCode.insertSpacesOverride": true
}
To edit these without memorising the namespace, open the Extensions view, find the extension, click the gear icon and choose Extension Settings. Changes apply on the next format — no window reload, no VS Code restart. To see what is actually winning when several sources define the same key, run Preferences: Open User Settings (JSON) and compare against your workspace and folder settings, because the most specific scope is the one that applies.
Worth knowing: sql-formatter is also published as a CLI with a .sql-formatter.json config file that accepts the same option names. If your team already runs it in CI, copy those values into the VS Code settings so the editor and the pipeline agree — otherwise every push reformats what the editor just wrote.
4. Prettier + prettier-plugin-sql
If your project already uses Prettier for JavaScript, TypeScript, CSS, or JSON, adding SQL support is straightforward with the prettier-plugin-sql plugin. This keeps your formatting toolchain unified across languages.
Setup
- Install Prettier globally or locally:
npm install --save-dev prettier
- Install the SQL plugin:
npm install --save-dev prettier-plugin-sql
- Create or update
.prettierrc in your project root:
{
"plugins": ["prettier-plugin-sql"],
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"keywordCase": "upper",
"language": "postgresql"
}
Format-on-Save with Prettier
In VS Code, install the Prettier - Code formatter extension, then add to settings.json:
{
"[sql]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
}
Now every SQL file formats automatically when saved, using your Prettier configuration.
Note: prettier-plugin-sql supports fewer dialects than the adpyke extension. If you work with T-SQL, PL/SQL, or Snowflake, prefer the dedicated SQL Formatter extension instead.
5. When Prettier, ESLint, and the SQL Extension Fight
Two extensions can register a formatter for the same document, and VS Code picks one silently. Here are the failure modes you will actually hit, and what to do about each one.
"There are multiple formatters for 'sql' files"
This notification appears the first time you save, and VS Code refuses to format until you choose. Click Configure... in the notification, or set the owner explicitly in settings.json:
{
"[sql]": {
"editor.defaultFormatter": "ReneSaarsoo.sql-formatter-vsc"
}
}
The value must be the extension's publisher.name identifier, not its display name. The three you are most likely to need are ReneSaarsoo.sql-formatter-vsc, adpyke.vscode-sql-formatter, and esbenp.prettier-vscode. Guessing the display name ("SQL Formatter") is the single most common reason this setting appears to do nothing.
Prettier cannot parse SQL without the plugin
If Prettier is your default formatter but you have not installed prettier-plugin-sql, saving a .sql file produces No parser could be inferred for file. Installing the plugin fixes the error — and creates a subtler problem: Prettier then formats the file with its own configuration and completely ignores the SQL-Formatter-VSCode.* keys. You now have two formatters with two independent configs, and which one runs depends on which extension won the default-formatter contest that day.
Pick one owner per file type. If Prettier owns .sql, configure the SQL options inside .prettierrc instead:
{
"plugins": ["prettier-plugin-sql"],
"language": "postgresql",
"keywordCase": "upper",
"expressionWidth": 80
}
If the SQL extension owns .sql, keep Prettier away from those files with a .prettierignore entry — otherwise a prettier --write . run in CI will rewrite the SQL the editor just formatted.
# .prettierignore
*.sql
migrations/**/*.sql
Prettier's global config leaking into SQL
printWidth, tabWidth, and useTabs from .prettierrc apply to SQL files too once the plugin is installed. That is why the same query can format one way in your editor and another way on a colleague's machine — one of you has a repo-level .prettierrc and the other does not. Keep the language-specific keys (keywordCase, language, expressionWidth) in the shared config so at least the casing and dialect are deterministic.
SQL inside JavaScript template literals
This is the conflict that actually wastes an afternoon. Prettier treats an sql`...` template literal as an opaque string and reindents the whole block without understanding it. To get real SQL formatting inside JS and TS you add prettier-plugin-embed with embeddedSqlTags: ["sql"], which hands the contents to prettier-plugin-sql. Meanwhile eslint-plugin-sql exposes a sql/format rule that formats tagged template literals as well — and can also flag unsafe concatenated queries via sql/no-unsafe-query.
Do not enable both. Choose the Prettier route (embed + sql plugins, one config, no lint rule) or the ESLint route (the sql/format rule with an options object for ignoreInline, ignoreTagless, and retainBaseIndent, plus a second options object that takes the sql-formatter configuration directly). Run both and every save reformats the same lines twice with slightly different rules, which shows up as permanent churn in every pull request.
Stop ESLint and Prettier fighting over the surrounding JS
Put eslint-config-prettier last in your extends array so ESLint switches off the stylistic rules Prettier already handles. Leave eslint-plugin-prettier out unless you specifically want Prettier failures reported as lint errors — if you keep it, at least there is one source of truth.
6. SQLFluff — For Teams and CI Pipelines
SQLFluff is a dialect-aware SQL linter and formatter that works as both a VS Code extension and a command-line tool. It is ideal for teams that need consistent SQL style enforced in CI/CD pipelines.
Installation
- Install the Python package:
pip install sqlfluff
- Install the VS Code extension: Search for "SQLFluff" in the Extensions marketplace
- Create a
.sqlfluff config file in your project root:
[sqlfluff]
dialect = postgresql
max_line_length = 100
[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper
[sqlfluff:rules:indentation]
indent_unit = space
tab_space_size = 2
When to Choose SQLFluff
- You need SQL linting and formatting in one tool
- Your team uses a CI pipeline that checks SQL style on every PR
- You work with complex SQL that needs rule-based validation (e.g., forbidden patterns, naming conventions)
SQLFluff is more opinionated and stricter than the other options. For simple formatting needs, the adpyke extension or Prettier plugin are faster to set up.
7. How to Enable Format-on-Save for SQL
Once you have installed a SQL formatting extension, the final step is turning on format-on-save so every SQL file is automatically cleaned up when you press Ctrl+S.
Global Format-on-Save
// settings.json
{
"editor.formatOnSave": true
}
This enables format-on-save for all file types. If you want it only for SQL files:
Language-Specific Format-on-Save
// settings.json
{
"[sql]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "adpyke.vscode-sql-formatter"
}
}
Verification
To verify it works:
- Open a
.sql file in VS Code
- Add messy SQL like
select * from users where id=1;
- Press Ctrl+S
- Watch the query reformat to
SELECT * FROM users WHERE id = 1;
If format-on-save does not trigger, check the VS Code Output panel (View > Output) and select "Log (Window)" from the dropdown. Look for errors from your formatter extension.
8. Formatting SQL in Jupyter Notebooks
Notebooks are a separate document type in VS Code, and almost none of the SQL formatting advice above applies unchanged. The first thing to know is that editor.formatOnSave does nothing here. Notebook formatting is gated behind its own setting:
{
"notebook.formatOnSave.enabled": true,
"notebook.defaultFormatter": "ReneSaarsoo.sql-formatter-vsc"
}
That gets you formatting on save for notebooks, but it will not format your SQL. A cell that runs %%sql is a Python cell with a magic at the top — its language is still Python, so the notebook routes it to the Python formatter and the SQL formatter never sees the contents. Nothing errors and nothing changes, which is the confusing part.
What actually works
- Keep long queries in
.sql files and load them. Write the query in reports/monthly_revenue.sql, then read it in the notebook: pd.read_sql(Path("reports/monthly_revenue.sql").read_text(), conn). You get format-on-save, syntax highlighting, linting, and — the real win — a query that shows up as a readable diff in code review instead of a wall of notebook JSON.
- Switch the cell language and use Format Cell. Click the language picker in the bottom-right of the cell, or run Change Cell Language from the Command Palette, set it to SQL, and format with Format Cell (command ID
notebook.formatCell, which you can bind to a key). The cell no longer runs the magic, so paste the formatted query back into your %%sql cell afterwards. Two steps, but it keeps everything on one screen.
- Format in the browser and paste back. For a one-off query in a scratch notebook, our online SQL formatter is faster than reconfiguring anything — format, copy, paste into the cell.
Why nothing happens, and how to check
notebook.formatOnSave.enabled only formats cells whose language has a registered formatter. Unknown or unsupported languages are skipped silently, with no entry in the Output panel and no notification. If a notebook refuses to format, open the cell's language picker first — if it says Python or Raw, that is your answer, and no amount of settings tweaking will change it.
9. Multi-Dialect Workspaces and Team-Shared Settings
A repository that touches PostgreSQL in one service and Snowflake in another cannot use a single user-level dialect setting. Two mechanisms solve this.
Per-folder settings in a multi-root workspace
A .code-workspace file lets each folder carry its own settings block, so the dialect is scoped to the project that needs it:
{
"folders": [
{ "path": "services/billing", "settings": { "SQL-Formatter-VSCode.dialect": "postgresql" } },
{ "path": "services/analytics", "settings": { "SQL-Formatter-VSCode.dialect": "snowflake" } }
],
"settings": {
"SQL-Formatter-VSCode.keywordCase": "upper"
}
}
Settings precedence runs from least to most specific: default, then user, then remote, then workspace, then the individual workspace folder. The folder entry always wins, which is exactly what you want here.
A committed .vscode/settings.json
For single-folder repos, commit .vscode/settings.json with the formatting configuration so a fresh clone behaves the same as a machine that has been set up for a year:
{
"SQL-Formatter-VSCode.dialect": "postgresql",
"SQL-Formatter-VSCode.keywordCase": "upper",
"[sql]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "ReneSaarsoo.sql-formatter-vsc"
},
"files.associations": {
"*.ddl": "sql",
"*.pgsql": "sql"
}
}
The files.associations block is the part people forget. VS Code does not treat .ddl, .pgsql, or .hql as SQL by default, so format-on-save never fires for them and the extension appears broken. Associating the extensions fixes it without touching the formatter.
Keep this file to formatting and editor behaviour. Font sizes, themes, and minimap preferences belong in user settings — putting them in the repo turns every personal preference change into a reviewed diff and a merge conflict.
Recommend the extension, do not assume it
Commit a .vscode/extensions.json so VS Code prompts new contributors to install the formatter:
{
"recommendations": ["ReneSaarsoo.sql-formatter-vsc"]
}
Skip this step and half the team ends up on the archived 2019 extension. The two builds read different setting namespaces, so a shared settings.json written for one is silently ignored by the other — the affected developers get default formatting and no error message telling them why.
Introducing a formatter to a mature repo: do the first full-repo format as its own commit with no logic changes in it. Then add that commit hash to a .git-blame-ignore-revs file and run git config blame.ignoreRevsFile .git-blame-ignore-revs. Without it, every line of every SQL file attributes to whoever ran the formatter, and git blame stops being useful for a year.
10. Using an Online SQL Formatter
Even with the best VS Code SQL formatter configured, there are times when you need to format SQL outside the editor — when reviewing a colleague's query in a pull request, pasting from an email, or working on a machine without your setup.
Format SQL Online — Free, No Signup
Paste your SQL query, select your dialect, and format instantly. Works for MySQL, PostgreSQL, SQL Server, and 12+ other dialects. All processing happens in your browser.
Open SQL Format Tool →
Our online formatter supports all the same dialects as the VS Code extensions: MySQL, PostgreSQL, T-SQL, BigQuery, Snowflake, SQLite, and more. It handles complex queries with CTEs, subqueries, window functions, and nested joins.
When to Use Each Tool
- VS Code extension: Your daily driver for writing and editing SQL files
- Online formatter: Quick formatting on any device, sharing clean SQL, or format-on-paste from external sources
- SQLFluff: Team-wide style enforcement and CI pipeline checks
11. FAQ — Format SQL in VS Code
What is the best SQL formatter extension for VS Code?
The most popular choice is the SQL Formatter extension by adpyke, which supports 15+ dialects and integrates with the sql-formatter library. For codebases already using Prettier, the prettier-plugin-sql plugin is a great option. Both support format-on-save.
How do I format SQL on save in VS Code?
Install a SQL formatting extension, then add "editor.formatOnSave": true to your VS Code settings.json. To scope it only to SQL files, use "[sql]": {"editor.formatOnSave": true, "editor.defaultFormatter": "adpyke.vscode-sql-formatter"}.
Does VS Code have a built-in SQL formatter?
No, VS Code does not include a built-in SQL formatter. You need to install an extension from the marketplace. The most common options are SQL Formatter (adpyke), Prettier with prettier-plugin-sql, or SQLFluff for linting plus formatting.
Can I format SQL online without installing an extension?
Yes. SQLFormat.io is a free online SQL formatter that supports 15+ dialects including MySQL, PostgreSQL, T-SQL, and more. Just paste your SQL, select the dialect, and format instantly — no installation required.
How do I configure multiple SQL dialects in one VS Code workspace?
Use a multi-root .code-workspace file and put a SQL-Formatter-VSCode.dialect value inside each folder's settings block, or set the dialect in each project's .vscode/settings.json. Folder-level settings take precedence over workspace, user, and default settings, so a Snowflake project and a PostgreSQL project can each format correctly side by side.
Does format-on-save work for SQL in Jupyter notebooks?
Not through editor.formatOnSave — notebook cells need notebook.formatOnSave.enabled instead, and a cell running %%sql magic is still a Python cell, so the SQL formatter never sees its contents. Keep long queries in a .sql file and load them into the notebook, or switch the cell language to SQL and run Format Cell on it.