我必须保持帐户余额最新,记录更改并使用它。
在我看来,选项是:
替代方案是:
有谁知道哪个更快?它有多少?
史蒂夫
答案 0 :(得分:0)
你提出的建议似乎太复杂了...... 我会做一些不同的事情: 我会有两个表与主 - 细节关系。 在详细信息中,我将插入行,其触发器将更新主表
balance (account, amount, ...)
balance_detail (account, amount, ...)
balance_detail_after_insert
begin
update master
set amount = amount + new.amount
where account = new.account;
end
balance_detail_after_update
begin
update master
set amount = amount + new.amount - old.amount
where account = new.account;
end
balance_detail_after_delete
begin
update master
set amount = amount - new.amount
where account = new.account;
end
任何更改后,您只需关闭/打开主表即可刷新数据。