SqlServer.Rules

MCP.Pizza Chef: ErikEJ

T-SQL Analyzer reviews SQL scripts and whole database projects against a large rule library, then reports what it finds: risky patterns, performance traps, and design or naming problems. Connected to GitHub Copilot Chat in VS Code or Visual Studio, you can ask for that review in plain language and get specific feedback back in the chat. Installation is a one-click button in either editor, and no account or key is needed. The same rules can also run automatically whenever a database project is built.

Coding
Data

Use This MCP server To

Check my SQL for common mistakes before I ship it Ask Copilot to review a stored procedure I just wrote Catch slow query patterns early in a database project Enforce the same SQL standards across a whole team Get a written list of issues in a folder of scripts

README

Static Analysis Rule-sets for SQL Projects

MCP Toplist

build status latest version GitHub Sponsors

Overview

A library of SQL best practices implemented as over 140 database code analysis rules checked at build time.

The rules can be added as NuGet packages to SQL Database projects:

For a complete list of the current rules we have implemented see here.

Component Stack

flowchart TD
    VS["Visual Studio T-SQL Analyzer<br/>Live feedback in Visual Studio"]
    SSMS["SSMS T-SQL Analyzer<br/>Live feedback in SQL Server Management Studio"]
    VSC["VS Code T-SQL Analyzer<br/>Live feedback in Visual Studio Code"]
    CLI["T-SQL Analyzer CLI<br/>tsqlanalyze command line tool"]
    CLILIB["ErikEJ.DacFX.TSQLAnalyzer (CLI NuGet library)<br/>Loads scripts and executes analysis"]
    MBSQL["SDK Style SQL Database Projects<br/>Build-time SQL Project analysis"]
    CLASSIC["Classic .sqlproj<br/>Build-time SQL Project analysis"]
    RULES["SqlServer.Rules<br/>Static SQL code analysis rules"]
    MCP["MCP Server<br/>AI Agent integration for SQL code analysis rules"]

    VS --> CLI
    SSMS --> CLI
    VSC --> CLI
    CLASSIC --> RULES
    CLI --> CLILIB
    CLILIB --> RULES
    MBSQL --> RULES
    MCP --> CLI
Loading

Usage

The latest version is available on NuGet

dotnet add package ErikEJ.DacFX.SqlServer.Rules

Modern SDK-style Projects

The rules are available as a NuGet package that can be added to your SQL Database project. The rules will run during build, and report any issues in the Error List window.

You can read more about using and customizing the rules in the docs here

Classic .sqlproj Projects

You can download and manually use the rules with Visual Studio and "classic" SQL Database projects, as described in my blog post here.

Command line tool - T-SQL Analyzer CLI

This repository also contains a .NET command line tool that uses the rule set.

You can use it to analyze SQL scripts or SQL Database projects and output the results in a variety of formats, including XML and JSON.

You can also use the tool as an MCP Server with GitHub Copilot in VS Code and Visual Studio, allowing you to get feedback on your SQL code using GitHub Copilot Chat.

The T-SQL 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 Install in VS Code VS Code MCP Official Guide
Visual Studio Install in Visual Studio Visual Studio MCP Official Guide

Read more in the dedicated readme file

Visual Studio extension - T-SQL Analyzer

This repository also contains a Visual Studio extension that uses the rule set.

Run live analysis of your SQL scripts in Visual Studio and get the results in the Error List window.

Download the extension from the Visual Studio Marketplace or get the CI build

Read more in the dedicated readme file

SQL Server Management Studio extension - T-SQL Analyzer

This repository also contains a SQL Server Management Studio extension that uses the rule set.

Run live analysis of your SQL scripts in SQL Server Management Studio and get the results in the Error List window.

Download the latest build of this extension from the SSMS VSIX Gallery

Read more in the dedicated readme file

VS Code extension - T-SQL Analyzer

This repository also contains a VS Code extension that uses the rule set.

Get live squiggles and diagnostics for your .sql files as you type in Visual Studio Code — no build step required.

Read more in the dedicated readme file

SqlServer.Rules FAQ

Which apps does it work in?
GitHub Copilot Chat in VS Code and Visual Studio, using the one-click install buttons in the project's readme.
Do I need an account or key?
No. It runs locally as a command line tool that your editor starts for you.
Can I use this to review a SQL script before a release?
Yes. Point it at a single script or an entire database project and it reports every rule it flags.
How many checks are there?
More than 140 rules covering SQL Server best practices, with the full list published in the project docs.
Does it change my SQL?
No. It reports the issues it finds and leaves every decision to you.
Does it work outside an assistant?
Yes. There are extensions for Visual Studio, SQL Server Management Studio, and VS Code, plus a command line tool.