Skip to main content
Glama
ErikEJ
by ErikEJ

Static Analysis Rule-sets for SQL Projects

build status latest version GitHub Sponsors

Overview

A library of SQL best practices implemented as more than 120 database code analysis rules checked at build.

The rules can be added as NuGet packages to modern SQL Database projects based on either MSBuild.Sdk.SqlProj or Microsoft.Build.Sql.

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

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

This fork also contains an additional set of rules TSQL Smells forked from TSQL-Smells

Related MCP server: Google Toolbox

Usage

The latest version is available on NuGet

dotnet add package ErikEJ.DacFX.SqlServer.Rules
dotnet add package ErikEJ.DacFX.TSQLSmellSCA

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

Command line tool - T-SQL Analyzer CLI

This repository also contains a .NET commmand line tool, that uses the rule sets.

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 a MCP Server with GitHub Copilot with 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 sets.

You can run live analysis of your SQL Database projects in Visual Studio, and get the results in the Error List window.

Download the extension from the or get the

Read more in the dedicated readme file

Solution Organization

.github - GitHub actions

docs - markdown files generated from rule inspection with the DocsGenerator unit test

Solution Items - files relating to build etc.

src

  • SqlServer.Rules - This holds the rules derived from SqlCodeAnalysisRule

  • TSQLSmellSCA - an additional set of rules TSQL Smells forked from TSQL-Smells

test

  • SqlServer.Rules.Tests - a few test to demonstrate unit testing of rules

  • TSQLSmellsSSDTTest - unit tests of some of the TSQL Smells rules

  • TestHelpers - shared test base classes

tools

  • SqlAnalyzerCli - a command line tool to run rules against a SQL Project

  • SqlAnalyzerVsix - a Visual Studio extension to run rules against a SQL Project

  • ErikEJ.DacFX.TSQLAnalyzer - library and NuGet package for running rules against SQL scripts and reporting results. Used by SqlAnalyzerCli

  • SqlServer.Rules.Generator - a quick console app to report on all rules in a SQL Project.

  • SqlServer.Rules.Report - Library for evaluating a rule and serializing the result.

sqlprojects

  • AW - AdventureWorks schema SQL Project for rules validation

  • TestDatabase - a small SQL Database Project with some rule violations

  • TSQLSmellsTest - a SQL Database Project with some rule violations

-
security - not tested
A
license - permissive license
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ErikEJ/SqlServer.Rules'

If you have feedback or need assistance with the MCP directory API, please join our Discord server