这句触发器的效率是不是很低?
CREATE TRIGGER [abc] ON dbo.a FOR INSERTASbegin update b set aNum=aNum+(select count(1) from inserted where aid=b.aid) returnerror: rollback transactionend
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 的数据是没变,可是一样执行了更新的操作