首页 > 开发 > 综合 > 正文

创建CLR自定义触发器-C#

2024-07-21 02:18:19
字体:
来源:转载
供稿:网友


第一步:在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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表