T-SQL Analyzer is a command line tool for identifying, and reporting the presence of anti-patterns in T-SQL scripts.
It evaluates more than 140 rules for design, naming and performance issues.
The tool runs on any system with the .NET 8.0 runtime installed.
dotnet tool install --global ErikEJ.DacFX.TSQLAnalyzer.Cli# Analyze all .sql scripts in current folder and sub-folders
tsqlanalyze
## Analyze a single file
tsqlanalyze -i C:\scripts\sproc.sql
## Analyze a folder
tsqlanalyze -i "c:\database scripts"
## Analyze a folder with a filter and a full folder path
tsqlanalyze -i c:\database_scripts\sp_*.sql "c:\old scripts"
## Analyze a script with a rule settings filter and for a specific SQL Server version
tsqlanalyze -i C:\scripts\sproc.sql -r Rules:-SqlServer.Rules.SRD0004 -s SqlAzure
## Analyze a .dacpac and save results to an xml file
tsqlanalyze -i C:\scripts\Chinook.dacpac -o result.xml
## Analyze a .dacpac and save results to a JSON file
tsqlanalyze -i C:\scripts\Chinook.dacpac -o result.json
## Analyze a .zip file with .sql files
tsqlanalyze -i C:\scripts\Fabric.zip
## Analyze a live database
tsqlanalyze -c "Data Source=.\SQLEXPRESS;Initial Catalog=Chinook;Integrated Security=True;Encrypt=false"
## Analyze a single file, and include path(s) to your own rules .dll file(s)
tsqlanalyze -i C:\scripts\sproc.sql -a C:\code\analyzers
## Analyze a single file, and reformat (PREVIEW)
tsqlanalyze -i C:\scripts\sproc.sql -f Rule settings filters are demonstrated here
The SQL Server version values are documented here
Note: UTF-8 with BOM encoding is required for the input files.
The tool will output a summary of the rules that were violated, and the line numbers where the violations occurred.
Table3.sql:
CREATE TABLE [dbo].[Table3]
(
[Id] INT NOT NULL,
[Wang] NCHAR(500) NOT NULL,
[Chung] NCHAR(10) NOT NULL
)You can use the tool to ask GitHub Copilot analyze your SQL Server CREATE scripts in Visual Studio or VS Code.
The TSQL Analyzer MCP Server supports quick installation across multiple development environments. Choose your preferred client below for streamlined setup:
| Client | One-click Installation | MCP Guide |
|---|---|---|
| VS Code | VS Code MCP Official Guide | |
| Visual Studio | Visual Studio MCP Official Guide |
Example JSON configuration:
{
"servers": {
"tsqlanalyzer": {
"type": "stdio",
"command": "dnx",
"args": [
"ErikEJ.DacFX.TSQLAnalyzer.Cli",
"--yes",
"--",
"-mcp"
]
}
}
}Inspired by the SQL Formatter Visual Studio extension from Mads Kristensen, the -f switch will enable formatting of the analyzed scripts using the ScriptDom library.
- Formats T-SQL code to a consistent and readable layout
- Customizable formatting rules
.editorconfigsupport
See this for information about the .editorconfig format.
See this for information about the available options.
Enabling this will cause your script files to be updated!
You can run the tool against any script in the SQL editor, if configured as an external tool.
From the main menu, select Tools, External Tools and configure as shown:
Title: tsqlanalyze
Command: C:\Users\<YourUserName>\.dotnet\tools\tsqlanalyze.exe
Arguments: -n -i $(ItemPath)
Use output window: ✓
To run the tool, select Tools, tsqlanalyze and the result will be displayed in the Output window. Double click a warning to navigate to the related script line.


