Create a CLR custom trigger -C #

xiaoxiao2021-03-06  65

The first step: using in the preparation of the 2005 Visual Studio Code System; using System.Data; using System.Data.Sql; using System.Data.SqlServer; using System.Data.SqlTypes; public partial class Triggers {// Enter existing table or view for the target and uncomment the attribute line // [SqlTrigger (Name = "myTrigger", target = "Table1", Event = "fOR UPDATE")] public static void myTrigger () {SqlTriggerContext myTriggerContext = SqlContext.GetTriggerContext () ; SqlPipe myPipe = SqlContext.GetPipe (); SqlCommand myCommand = SqlContext.GetCommand (); if (myTriggerContext.TriggerAction == TriggerAction.Insert) {myCommand.CommandText = "select * from spTestTbl";} myPipe.Execute (myCommand); }

Step 2: Compilation, Deployment (BUILD, Deploy) Step 3: Register to YUKON Syntax: Create Trigger Trigger_name on Table_name for Insert | Update | Delete As External Name Assembly_name.class_name.clr_trigger_name

Example: CREATE TRIGGER MyTrigger on testtbl1 for Insert As External Name Udt.triggers.mytrigger

转载请注明原文地址:https://www.9cbs.com/read-82177.html

New Post(0)