VSCode SQL Formatter — The Complete Setup Guide
Published: July 8, 2026 | Updated: July 8, 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
- Prettier + prettier-plugin-sql
- SQLFluff — For Teams and CI Pipelines
- How to Enable Format-on-Save for SQL
- 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. 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.
4. 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.
5. 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.
6. 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
7. 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.