Walkthrough authoring a custom static Code Analysis rule assembly for SQL Server
This walkthrough demonstrates the steps used to create a SQL Server code analysis rule. The
This walkthrough demonstrates the steps used to create a SQL Server code analysis rule. The
rule created in this walkthrough is used to avoid
statements in stored
procedures, triggers, and functions.
In this walkthrough, you create a custom rule for Transact-SQL static code analysis by using the
following steps:
- Create a class library project, enable signing for that project, and add the necessary
references.
-
Create two helper C# classes.
-
Create a C# custom rule class.
-
Build the class library project.
-
Install and test the new code analysis rule.
Except for the Visual Studio (SQL Server Data Tools) instructions, the guide focuses on SDK-
style SQL projects.
You need the following components to complete this walkthrough:
A version of Visual Studio installed, which includes SQL Server Data Tools, and supports
C#.NET Framework development.
A SQL Server project that contains SQL Server objects.
An instance of SQL Server to which you can deploy a database project.
This walkthrough is intended for users who are already familiar with the SQL Server features of
Data Tools. You should be familiar with Visual Studio concepts, such as how to
create a class library, add NuGet packages, and how to use the code editor to add code to a
class.
First create a class library. To create a class library project:
-
Create a C# (.NET Framework) class library project named.
-
Rename the file
to.
WAITFOR DELAY
SampleRules
Class1.cs
AvoidWaitForDelayRule.cs