如何创建一个数据发生变化时触发的触发器???
如何创建一个数据发生变化时触发的触发器???
而不是ALTER TRIGGER updatebase ON dbo.Table for update
如果现有数据是"OK" updata Table set Name='OK' 虽然表执行了Update 但其实值还没有变。
这种情况下我不要他触发。 就是原值跟update后的值不一样了,才触发,一样的情况下不触发。
有没有办法实现这样的触发器!!
[解决办法]
ALTER TRIGGER updatebase
ON dbo.tb
for update
as
update otherTB set col=a.col from(
select a.* from inserted a inner join deleted b on a.id=b.id
and a.col<>b.col) a where otherTB.id=a.id
ALTER TRIGGER updatebase
ON dbo.Table1 for update
as
select *
from deleted as d
inner join dbo.Table1 as t on d.ID=t.ID and d.Name<>t.Name
ALTER TRIGGER updatebase
ON dbo.Table1 for update
as
if exists(select *
from deleted as d
inner join dbo.Table1 as t on d.ID=t.ID and d.Name<>t.Name)
begin
--your code
end
else
begin
--your code
end