在不禁用触发器的情况下限制触发器触发 [英] Restrict Trigger to fire without disabling the trigger

查看:96
本文介绍了在不禁用触发器的情况下限制触发器触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在sql server中有一个表称为employee,其中有empid和empname作为列

我有触发器,可以登录员工变更历史记录.

我有一个存储过程,下面是SP中的查询

1)从员工那里删除Empid = @ Empid
2)插入到员工中SELECT @ Empid,@ EmpName
3)从员工那里删除,其中Empname = @ EmpName


我知道以上三个陈述并不意味着完整,但以上仅仅是对理解的一个例子.

现在,我要在执行不会触发删除触发器"的第一条语句时进行一些更改".
但是我希望它在第三个删除查询上触发.

Hello All ,

I have one table in sql server called as employee which has empid and empname as columns

I have trigger in place which will log in employee changes history.

I have one stored procedure and below are the queries in the SP

1) Delete from Employee where Empid=@Empid
2) Insert Into Employee SELECT @Empid,@EmpName
3) Delete from Employee where Empname=@EmpName


I know above three statement is not meaning full but Above is just an example to sort the understanding.

Now I want "some changes" while executing the first statement where "Delete Trigger" will not fire.
But I want it to be fired on third delete query .

推荐答案

我认为您需要创建一个存储计数的表,除非有可变机制在SQL Server中,然后增加您的计数器,当计数器增加到三时,执行您的操作.我希望您可以将此代码放入触发器中,因此它始终会触发,但仅在您希望的时候起作用.
I would think you need to create a table that stores a count, unless there''s a variable mechanism in SQL Server, then increment your counter and when it gets to three, perform your action. I expect you''ll put this code inside your trigger, so it always fires, but only acts when you want it to.


这篇关于在不禁用触发器的情况下限制触发器触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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