[marketplace]: [vsixgallery]: [repo]: # T-SQL Analyzer ## Live Code Analysis for SQL scripts in Visual Studio [![Build](https://github.com/ErikEJ/SqlServer.Rules/actions/workflows/vsix.yml/badge.svg)](https://github.com/ErikEJ/SqlServer.Rules/actions/workflows/vsix.yml) ![GitHub Sponsors](https://img.shields.io/github/sponsors/ErikEJ) Download this extension from the [Visual Studio Marketplace][marketplace] or get the [CI build][vsixgallery] ---------------------------------------- Analyze your SQL scripts as you type, and get suggestions for improvements based on best practices. The analyzer has over [140 rules](https://github.com/ErikEJ/SqlServer.Rules/blob/master/docs/readme.md) covering performance, security, maintainability, and more. ![editor](Images/editor.png) The extension works with both SQL Server and Azure SQL Database projects based on [MSBuild.Sdk.SqlProj](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj) or [Microsoft.Build.Sql](https://github.com/microsoft/DacFx/tree/main/src/Microsoft.Build.Sql) as well as classic [SQL database projects](https://learn.microsoft.com/sql/tools/sql-database-projects/get-started?view=sql-server-ver17&pivots=sq1-visual-studio). The extension will respect any rule configuration you have in your SQL project, including whether analysis is enabled, SQL version and rule suppression. ```xml net10.0 Sql170 True -SqlServer.Rules.SRD0006 -SqlServer.Rules.SRD0006;-Microsoft.* ``` In addition, the extension supports analysis of any SQL script in your editor, whether it is part of a project or not. You can customize the behavior of the extension via Tools/Options. ### Customizing Rules All rules are enabled by default. You can fine-tune them in Tools/Options using a simple expression: | Promote a rule to an error | `+!SqlServer.Rules.SRN0001` | | Combine several | `-SqlServer.Rules.SRD0004;+!SqlServer.Rules.SRN0001` | | Disable a single rule | `-SqlServer.Rules.SRD0004` | | Disable all naming rules | `-SqlServer.Rules.SRN*` | | Promote a rule to an error | `+!SqlServer.Rules.SRN0005` | | Combine several | `-SqlServer.Rules.SRD0004;+!SqlServer.Rules.SRN0005` | You can set this expression in the `Rules expression` option under Tools/Options when a SQL project rule configuration is not available. The extension also adds a menu item under `Tools` to run the T-SQL Analyzer against the currently open SQL script in the editor. ![toolsmenu](Images/toolsmenu.png) ### Analysis Errors If a script cannot be fully modeled or an analysis rule fails, the available findings are still shown in the Error List. Details of these errors (kind, code, and message) are written to the **T-SQL Analyzer** pane in **View > Output**. Findings may be incomplete until these errors are resolved. ### Installation Requirements - The extension automatically uses the .NET 10 `dnx` command to run the T-SQL Analyzer CLI tool as a NuGet package. No separate installation is required. - The [.NET 10 SDK](https://dotnet.microsoft.com/en-us/download) is required and is automatically installed with the multiple workloads in Visual Studio. ## How can I help? If you enjoy using the extension, please give it a ★★★★★ rating on the [Visual Studio Marketplace][marketplace]. Should you encounter bugs or have feature requests, head over to the [GitHub repo][repo] to open an issue if one doesn't already exist. Another way to help out is to [sponsor me on GitHub](https://github.com/sponsors/ErikEJ). If you would like to contribute code, please fork the [GitHub repo][repo] and submit a pull request.