Analyze your SQL CREATE scripts for best practices relating to design, naming and performance as you author them in Visual Studio.

Background

I maintain a collection of over 140 open source static code analysis rules based on the DacFX API for T-SQL based best practices analyzers.

To make the most of the rules, I publish them on NuGet in various forms, so you can take advantage of them in various contexts:

Presenting T-SQL Analyzer

The latest member of the family is a Visual Studio extension, that provides live analysis of your script as you work with it in the Visual Studio SQL editor.

It supports projects based on our MSBuild.Sdk.SqlProj build SDK as well as Microsoft.Build.Sql projects, and legacy Visual Studio SQL database projects.

editor

The extension will respect any rule configuration you have in your SQL project, including whether analysis is enabled, SQL version and rule suppression.

<Project Sdk="MSBuild.Sdk.SqlProj/3.2.0">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <SqlServerVersion>Sql170</SqlServerVersion>
    <RunSqlCodeAnalysis>True</RunSqlCodeAnalysis>
    <CodeAnalysisRules>-SqlServer.Rules.SRD0006;-Smells.*</CodeAnalysisRules>
  </PropertyGroup>
</Project>

The extension also adds a menu item under Tools to run the T-SQL Analyzer tool against the currently open SQL script in the editor.

toolsmenu

The extension depends on the T-SQL Analyzer CLI tool, which is installed as a .NET global tool. If you haven't installed the tool yet, you can do so by running the following command in a terminal:

dotnet tool install -g ErikEJ.DacFX.TSQLAnalyzer.CLI

Download the extension from the Visual Studio Marketplace

Should you encounter bugs or have feature requests, head over to the GitHub repo to open an issue if one doesn't already exist.