VS2005创建CLR自定义触发器
生活随笔
收集整理的這篇文章主要介紹了
VS2005创建CLR自定义触发器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第一步:在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?
?
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?
?
總結
以上是生活随笔為你收集整理的VS2005创建CLR自定义触发器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求一个好听的雕塑名字
- 下一篇: C语言100个经典的算法