标签:
在CLR编写一个插入娄据的触发器。
这个触发器是当对表插入数据时,即时把刚才插入的数据显示出来:
可复制代码:
public static void tri_RetrieveJustInsertedData() { SqlCommand command; SqlTriggerContext triggContext = SqlContext.TriggerContext; SqlPipe pipe = SqlContext.Pipe; SqlDataReader sdr; switch (triggContext.TriggerAction) { case TriggerAction.Insert: using (SqlConnection connection = new SqlConnection(@"context connection=true")) { connection.Open(); command = new SqlCommand(@"SELECT [Fruit_nbr],[FruitKind_nbr],[FruitName] FROM INSERTED;", connection); sdr = command.ExecuteReader(CommandBehavior.SingleRow); while (sdr.Read()) { string result = (byte)sdr["Fruit_nbr"] + " " + (byte)sdr["FruitKind_nbr"] + " " + (string)sdr["FruitName"]; pipe.Send(result); } } break; } }
当点击"OK"铵钮之后,可以看到:
然后在数据查询分析器,执行下面代码:
标签:
原文地址:http://www.cnblogs.com/insus/p/4415042.html