SqlTriggerAttribute 類別

定義

用於將組件中的方法定義標記為觸發程序 (Trigger)。 該屬性 (Attribute) 上的屬性 (Property) 反映使用 SQL Server 註冊型別時使用的實體屬性 (Attribute)。 此類別無法獲得繼承。

public ref class SqlTriggerAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)]
[System.Serializable]
public sealed class SqlTriggerAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)>]
[<System.Serializable>]
type SqlTriggerAttribute = class
    inherit Attribute
Public NotInheritable Class SqlTriggerAttribute
Inherits Attribute
繼承
SqlTriggerAttribute
屬性

範例

下列範例顯示 SqlTriggerAttribute 指定觸發程式的名稱、目標資料表,以及將引發觸發程式的事件。 如需完整的觸發程式範例,請參閱 SqlTriggerContext

[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;
   }
}
<SqlTrigger(Name:="SalesAudit", Target:="[dbo].[SalesInfo]", Event:="FOR INSERT")> _
Public Shared Sub SalesAudit()
        
   Dim triggContext As SqlTriggerContext
         
   ' Get the trigger context.
   triggContext = SqlContext.TriggerContext        

   Select Case triggContext.TriggerAction
      Case TriggerAction.Insert
      
      ' Do something in response to the INSERT.
         
   End Select

End Sub

備註

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

建構函式

SqlTriggerAttribute()

組件中方法定義上的屬性,用於將方法在 SQL Server 中標記為觸發程序。

屬性

Event

觸發程序的類型,以及何種資料操作語言 (DML) 動作會啟動觸發程序。

Name

觸發程序的名稱。

Target

觸發程序套用至的資料表。

適用於