SqlTriggerAttribute Classe

Definição

Usado para marcar uma definição de método em um assembly como um gatilho no SQL Server. As propriedades do atributo refletem os atributos físicos usados quando o tipo é registrado no SQL Server. Essa classe não pode ser herdada.

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
Herança
SqlTriggerAttribute
Atributos

Exemplos

O exemplo a seguir mostra a SqlTriggerAttribute especificação do nome do gatilho, da tabela de destino e do evento que disparará o gatilho. Confira SqlTriggerContext o exemplo de gatilho completo.

[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

Comentários

Consulte "Gatilhos CLR" no SQL Server 2005 Books Online para obter mais informações sobre gatilhos CLR e exemplos.

Construtores

SqlTriggerAttribute()

Um atributo em uma definição de método em um assembly, usado para marcar o método como um gatilho no SQL Server.

Propriedades

Event

O tipo de gatilho e qual ação DML (linguagem de manipulação de dados) o ativa.

Name

O nome do gatilho.

Target

A tabela à qual o gatilho se aplica.

Aplica-se a