Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 3.28 KB

create-clr-triggers.md

File metadata and controls

48 lines (34 loc) · 3.28 KB
title description author ms.author ms.reviewer ms.date ms.service ms.topic helpviewer_keywords
Create CLR Triggers
Learn how to create a user-defined trigger object inside SQL Server that is programmed in a CLR assembly.
MikeRayMSFT
mikeray
randolphwest
12/27/2024
sql
conceptual
CRL triggers
DML triggers, CLR triggers
DDL triggers, CLR triggers

Create CLR triggers

[!INCLUDE SQL Server]

You can create a database object inside [!INCLUDE ssNoVersion] that is programmed in an assembly created in the [!INCLUDE dnprdnshort] common language runtime (CLR). Database objects that can use the rich programming model provided by the CLR include DML triggers, DDL triggers, stored procedures, functions, aggregate functions, and types.

Creating a CLR trigger (DML or DDL) in [!INCLUDE ssNoVersion] involves the following steps:

  • Define the trigger as a class in a .NET Framework-supported language. For more information about how to program triggers in the CLR, see CLR Triggers. Then, compile the class to build an assembly in the [!INCLUDE dnprdnshort] using the appropriate language compiler.

  • Register the assembly in [!INCLUDE ssNoVersion] using the CREATE ASSEMBLY statement. For more information about assemblies in [!INCLUDE ssNoVersion], see Assemblies (Database Engine).

  • Create the trigger that references the registered assembly.

Note

Deploying a SQL Server Project in [!INCLUDE vsprvs] registers an assembly in the database that was specified for the project. Deploying the project also creates CLR triggers in the database for all methods annotated with the SqlTrigger attribute. For more information, see Deploy CLR database objects.

Executing CLR code is off by default in [!INCLUDE ssNoVersion]. You can create, alter, and drop database objects that reference managed code modules, but these references don't execute in [!INCLUDE ssNoVersion], unless the clr enabled server configuration option is enabled by using sp_configure.

Create, modify, or drop an assembly

Create a CLR trigger

Related content