SqlTriggerAttribute Class

Definition

Used to mark a method definition in an assembly as a trigger in SQL Server. The properties on the attribute reflect the physical attributes used when the type is registered with SQL Server. This class cannot be inherited.

C#
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)]
[System.Serializable]
public sealed class SqlTriggerAttribute : Attribute
Inheritance
SqlTriggerAttribute
Attributes

Examples

The following example shows the SqlTriggerAttribute specifying the name of the trigger, the target table, and the event that will fire the trigger. See SqlTriggerContext for the full trigger example.

C#
[SqlTrigger(Name = @"SalesAudit", Target = "[dbo].[SalesInfo]", Event = "FOR INSERT")]
public static void SalesAudit()
{
   // Get the trigger context.
   SqlTriggerContext triggContext = SqlContext.TriggerContext;

   switch (triggContext.TriggerAction)
   {
      case TriggerAction.Insert:

      // Do something in response to the INSERT.

      break;
   }
}

Remarks

See "CLR Triggers" in SQL Server 2005 Books Online for more information on CLR triggers and examples.

Constructors

SqlTriggerAttribute()

An attribute on a method definition in an assembly, used to mark the method as a trigger in SQL Server.

Properties

Event

The type of trigger and what data manipulation language (DML) action activates the trigger.

Name

The name of the trigger.

Target

The table to which the trigger applies.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1