T-SQL Analyzer is a free, open-source new command line tool for identifying, and reporting the presence of anti-patterns in SQL Server T-SQL scripts.

It evaluates more than 140 rules for design, naming and performance issues.

If you already maintain your SQL scripts in a SQL Database project, use build analysis as described in my blog post here.

This tool is for ad-hoc, commandline based analysis of individual scripts.

Getting started

The tool runs on any system with the .NET 8.0 runtime installed.

Installing the tool

dotnet tool install --global ErikEJ.DacFX.TSQLAnalyzer.Cli

Usage

# Analyze all scripts in current folder and sub-folders
tsqlanalyze

## Analyze a single script
tsqlanalyze -i C:\scripts\sproc.sql

## Analyze scripts in a folder
tsqlanalyze -i "c:\database scripts"

## Analyze scripts in folders with a wildcard path and a full folder path
tsqlanalyze -i c:\database_scripts\sp_*.sql "c:\old scripts"

## Analyze a script with a rule filter
tsqlanalyze -i C:\scripts\sproc.sql -r Rules:-SqlServer.Rules.SRD0004

## Analyze a script for a specific SQL Server version
tsqlanalyze -i C:\scripts\sproc.sql -s SqlAzure

You can exclude individual rules and rule categories with a "Rules:" statement, you can read more about the syntax for this here.

You can specify that your script targets a particular SQL Server version, using a SQL Server version enumeration value as documented here.

Sample output

The tool will output a summary of the rules that were violated, and the line numbers where the violations occurred.

CREATE TABLE [dbo].[Table3]
(
    [Id] INT NOT NULL, 
    [Wang] NCHAR(500) NOT NULL,
    [Chung] NCHAR(10) NOT NULL
)

Feedback

If you encounter any issue with the tool, or have suggestions, please create an issue here.