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