日期:2014-05-18 浏览次数:20497 次
CREATE TRIGGER [abc] ON dbo.a FOR INSERT AS begin update b set aNum=aNum+(select count(1) from inserted where aid=b.aid) return error: rollback transaction end
update b set aNum=aNum+(select count(1) from inserted where aid=b.aid) where b.aid in (select distinct(aid) from inserted)
update b set aNum=aNum+(select count(1) from inserted where aid=b.aid) where exists(select 1 from inserted where aid=b.aid)
------解决方案--------------------
第一个写法效率是很低,因为将整个表的b字段都更新了,虽然有些aid != b.aid 的数据是没变,可是一样执行了更新的操作