VS2005创建CLR自定义触发器

第一步:在VisualStudio2005中编写代码usingSystem;usingS数据库
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码

第一步:在Visual Studio 2005中编写代码

using 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);

}

}

第二步:编译,部署(Build,Deploy)

第三步:注册到Yukon

语法:

CREATE TRIGGER trigger_name ON table_name FOR INSERT|UPDATE|DELETE

AS EXTERNAL NAME assembly_name.class_name.clr_trigger_name

示例:

CREATE TRIGGER myTrigger ON testTbl1 FOR INSERT

AS EXTERNAL NAME udt.Triggers.myTrigger 

 

本文来源21aspnet,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/2073

发表评论