有效的SQL Server触发器-仅触发一次 [英] SQL Server Trigger that works - fires just once

查看:207
本文介绍了有效的SQL Server触发器-仅触发一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表数据更改后,我想进行一些计算。但是,我正在手动更新表并一次复制粘贴约3000行。这使我的触发器可以工作3000次,但是我只希望它执行一次触发器。

I want to do some calculations when my table data is changed. However, I am updating my table manually and copy pasting about 3000 rows in once. That makes my trigger work 3000 times, but I want it to do the trigger only once.

有办法吗?

谢谢。

推荐答案

如果通过手动表示您要复制并粘贴到某些用户界面工具(如Access dataGrid)中这样,该工具可能每行发出一个插入语句,在这种情况下,您不走运,数据库触发器将针对每个插入语句执行一次。如其他答案所述,如果您可以使用单个插入语句将行直接插入数据库中,则触发器将仅触发一次。

If by 'manually' you mean you are copying and pasting into some User Interface tool (like an Access dataGrid) or something like that, then the tool may be issuing one insert statement per row, and in that case you are out of luck the database trigger will be executed once per insert statement. As other answers have mentioned, if you can insert the rows directly into the database, using a single insert statement, then the trigger will only fire once.

这篇关于有效的SQL Server触发器-仅触发一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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