如何测试SQL Server触发器中的多行操作? [英] How to test for multiple row actions in a SQL Server trigger?

查看:257
本文介绍了如何测试SQL Server触发器中的多行操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的幼儿园SQL Server告诉我触发器可能会在插入和删除的伪表中触发多行。我大多写我的触发器代码与这一点,通常导致一些基于光标的污泥。现在我真的只能够测试他们一次击发单排。如何生成多线程触发器,SQL Server实际上是否会发送多线程触发器?我可以设置一个标志,以便SQL Server只会触发单行触发器

My kindergarten SQL Server taught me that a trigger may be fired with multiple rows in the inserted and deleted pseudo tables. I mostly write my trigger code with this in mind, often resulting in some cursor based cludge. Now I'm really only able to test them firing for a single row at a time. How can I generate a multirow trigger and will SQL Server actually ever send a multirow trigger? Can I set a flag so that SQL Server will only fire single row triggers??

推荐答案

一行,它应该由单个触发器调用处理,因为您可能想要还原整个事务。它不可能将其拆分为单独的触发器调用在逻辑上,我不认为SQL Server提供这样的标志。您可以通过发出影响多行的UPDATE或DELETE语句使SQL Server调用多行的触发器。

Yes, if a statement affects more than one row, it should be handled by a single trigger call, as you might want to revert the whole transaction. It is not possible to split it to separate trigger calls logically and I don't think SQL Server provides such a flag. You can make SQL Server call your trigger with multiple rows by issuing an UPDATE or DELETE statement that affects multiple rows.

这篇关于如何测试SQL Server触发器中的多行操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆