SSMS SQL Formatter

Tutorial · SQL Server Management Studio 21 / 22

Format Transact-SQL in SQL Server Management Studio

Use the free SSMS SQL Formatter extension to format a document or selection, choose a consistent style, automate formatting for a team, and use schema-aware tools without leaving SSMS.

DesignAlign · Published 29 August 2026 · About 12 minutes

Independent extension: SSMS SQL Formatter is a third-party, MIT-licensed DesignAlign product. It is not the Microsoft MSSQL extension for Visual Studio Code and is not produced or endorsed by Microsoft.

What SSMS SQL Formatter is

SSMS SQL Formatter adds T-SQL formatting directly to the query editor in SQL Server Management Studio (SSMS) 21 and 22. It can format an entire query window or only the selected text, and the change is applied as one editor operation so Ctrl+Z reverses it.

The default rule-based engine uses Microsoft ScriptDom locally. This makes formatting deterministic, fast, and available without an internet connection. An optional AI engine is available when you want free-form style instructions or exact comment placement, but it is never required.

Before
select o.OrderId,c.CustomerName,o.OrderDate
from dbo.Orders o join dbo.Customers c
on c.CustomerId=o.CustomerId
where o.Status='Open' and o.OrderDate>='2026-01-01'
order by o.OrderDate
After
SELECT   o.OrderId,
         c.CustomerName,
         o.OrderDate
FROM     dbo.Orders AS o
         INNER JOIN dbo.Customers AS c
             ON c.CustomerId = o.CustomerId
WHERE    o.Status = 'Open'
         AND o.OrderDate >= '2026-01-01'
ORDER BY o.OrderDate;

Prerequisites

Before you install the extension, make sure you have:

SSMS extension support: Microsoft does not officially support third-party extensions in SSMS 21/22. Keep the downloaded VSIX so you can remove or reinstall it with VSIXInstaller if needed.

Install SSMS SQL Formatter

  1. Download the current VSIX.

    Open the SSMS SQL Formatter page on Visual Studio Marketplace and choose Download. The extension is free.

  2. Close SSMS.

    Closing all SSMS windows lets the VSIX installer update the extension files safely.

  3. Run the downloaded file.

    Double-click SsmsSqlFormatter.vsix. If the installer lists SQL Server Management Studio as a target, select it and continue.

  4. Restart SSMS.

    Open a query window. The SQL Formatter toolbar should appear when the extension first loads, and the commands will also be available from the Tools menu.

If double-clicking the VSIX does not list SSMS, run the VSIX installer from the SSMS installation directory. Adjust 21 to 22 if necessary:

"C:\Program Files\Microsoft SQL Server Management Studio 21\Release\Common7\IDE\VSIXInstaller.exe" SsmsSqlFormatter.vsix

Format a document or selection

  1. Open a T-SQL query.

    Use an existing .sql file or create a new query in SSMS.

  2. Optionally select part of the script.

    If text is selected, only that selection is formatted. If there is no selection, the extension formats the whole document.

  3. Run Format T-SQL Script.

    Press Ctrl+Shift+Alt+F, use Tools > Format T-SQL Script, or click the formatter toolbar button.

  4. Review the result.

    Press Ctrl+Z once if you want to restore the original text.

Safer review: Choose Tools > Preview Format to compare the original and proposed SQL before applying it. This is particularly useful when testing a new custom style or reviewing a large script.

Some SSMS builds use a private editor context menu, so the right-click command may not appear automatically. The keyboard shortcut and Tools menu remain available. You can add the command manually through Tools > Customize > Commands.

Choose and configure a formatting style

Open Tools > Options > Format T-SQL Script. The General page controls the formatting engine and style.

StyleBest forBehaviour
ClassicCompact, familiar SQL layoutsFewer forced line breaks, trailing commas, and denser JOIN formatting.
ModernReadable reviews and longer queriesColumns, JOINs, and predicates are separated and aligned more visibly.
CustomHouse styles and team standardsUses your chosen casing, indentation, comma placement, line-break, alignment, semicolon, comment, and spacing options.

Custom settings include keyword, function, and data-type casing; indent size; comma placement; multiline lists; clause and predicate line breaks; JOIN, CASE, and assignment alignment; semicolon insertion; blank-line spacing; and comment handling.

Handle comments deliberately

ScriptDom produces a new script from its parse tree, so the rule-based engine needs a policy for comments:

Use the AI engine if exact comment position matters more than fully offline, deterministic formatting.

Automate formatting and share one team style

Format on save or paste

Enable Format on save to format each .sql document immediately before SSMS writes it to disk. Enable Format on paste to format multi-line SQL after a paste without affecting ordinary typing. Both features always use the local rule-based engine: they never wait for an AI request or send pasted SQL over the network.

Format multiple files

A script that does not parse is reported and left unchanged.

Use the same configuration in SSMS and CI

Export formatter settings to JSON, or place a file named .sqlformatter.json in a repository folder. Formatting a SQL file beneath that folder automatically discovers the configuration without changing the developer's personal Tools > Options settings.

The standalone rule-based CLI uses the same format:

ssmssqlfmt check <file-or-directory...> [--config settings.json]
ssmssqlfmt format <file-or-directory...> [--config settings.json]

check exits with code 1 when any SQL file would change, so it can gate a pull request or build. Directory inputs are searched recursively for *.sql files.

Use the schema-aware and export tools

Expand SELECT *

Tools > Expand SELECT * replaces SELECT * or alias.* with the ordered columns of a base table or view resolved through the active query connection. If the source cannot be resolved confidently, that occurrence is left untouched—the extension does not guess.

This works with ordinary tables and views, supported SQL Server catalogue objects, and SQL Server linked-server references. CTEs, derived tables, temporary objects, table variables, table-valued functions, synonyms, and non-SQL Server linked servers are intentionally left unchanged.

Annotate Script and Remove Annotations

Annotate Script adds comments next to resolvable SELECT, JOIN, and WHERE columns. Depending on the server and selected options, annotations can include type and nullability, documentation, relationships, sensitivity or masking facts, CHECK constraints, computed expressions, quality warnings, and script-versus-schema discrepancies.

It can also flag likely SQL mistakes such as = NULL, type-conflicting literal comparisons, and a null check against a non-nullable column. Annotations are additive comments only; the command does not rewrite query logic. Remove Annotations removes comments carrying the configured annotation label in one undoable operation.

Export results to Excel or CSV

Click inside an SSMS results grid, select the cells, and press Ctrl+Shift+Alt+X. The default Excel output protects identifiers and leading zeros by treating cells as text, and can include bold headers, banded rows, borders, a frozen header row, AutoFilter, and a separate Query sheet. CSV output and a fixed or prompted destination folder are also available.

Results-grid menus: SSMS builds a private context menu for its results grid. Use the keyboard shortcut, Tools menu, or a toolbar button when the formatter commands do not appear on right-click.

Choose between the rule-based and AI engines

EngineWhat happensUse it when
Rule-basedMicrosoft ScriptDom parses and regenerates T-SQL entirely on the local computer.You want fast, repeatable, offline formatting for editing, save/paste automation, batch jobs, or CI.
AIThe script is sent to the Anthropic or OpenAI-compatible provider and model that you configure.You need free-form instructions, SQLCMD-style input, or exact comment placement and accept the privacy and network trade-off.

AI credentials are stored for the current user in Windows Credential Manager, not as plain text in the settings file. Confirmation before sending is enabled by default. Review scripts for secrets, personal information, or production data before allowing them to leave the computer.

If the AI request fails, the extension can fall back to the rule-based engine when that option is enabled. Format on save, format on paste, batch formatting, and the CLI remain rule-based only.

Troubleshooting

SymptomWhat to check
The script was not changed.Rule-based formatting leaves SQL untouched when ScriptDom reports a parse error. Correct the reported line and column, or use AI for SQLCMD directives such as :setvar and :connect.
The editor right-click command is missing.Use Ctrl+Shift+Alt+F or the Tools menu. Add the command through Tools > Customize if you want it in the editor context menu.
Expand SELECT * or Annotate Script does nothing.Confirm the query window has an active database connection and uses a resolvable base table or view. Ambiguous and unsupported sources are deliberately skipped.
Tools > Options fails after an upgrade.Close SSMS, uninstall/reinstall the VSIX, and clear the affected SSMS ComponentModelCache. Maintainers can use the repository's tools/ssms-diagnose-and-reset.ps1 helper.
Comments moved.Check the General page's comment-handling option. Use Inline or MoveToEnd for rule-based formatting, or use AI when exact original placement is required.

Frequently asked questions

Can I format only selected SQL?

Yes. Select the T-SQL and run Format T-SQL Script. With no selection, the extension formats the full document.

Does formatting require an internet connection?

No. The rule-based engine, save/paste automation, batch formatting, and CLI work locally. Only the optional AI engine needs a network connection.

Will a syntax error damage my script?

No. The rule-based engine reports the parse error and leaves the script unchanged. Normal interactive formatting also remains one undoable editor operation.

Can a team enforce one formatting style?

Yes. Commit .sqlformatter.json with the repository and use ssmssqlfmt check in CI. Developers and CI then use the same rule-based settings.

Is SSMS SQL Formatter the same as Microsoft's VS Code SQL formatter?

No. Microsoft's formatter is part of the MSSQL extension for Visual Studio Code. SSMS SQL Formatter is an independent DesignAlign VSIX for SQL Server Management Studio 21/22. Both can use Microsoft ScriptDom, but their installation, interface, settings, and feature sets are different.