修改后,只需关闭/打开主表即可刷新数据。
我必须保持最新的账户余额,记录更改,并使用它。
在我看来,选项是:
- 保持单行,
- 使用触发器将更改保存到单独的表
- 使用select|update执行更新
- 使用简单的select从表中访问值
可选:
- 将值保留在单独的表中,
- 使用Select Last和Insert来实现更新
- 使用单独表中的Select Last来访问值
有人知道哪个更快吗?里面有很多东西吗?
史蒂夫你的建议似乎太复杂了…我建议做一件不同的事情:我将有两个具有主从关系的表。在细节中,我将插入行,它的触发器将更新主表
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