sql server - Does Persisted Computed Column need to update all rows or just affected rows? -


in stackoverflow article, understand persist mean , advantages , disadvantages. however, tried research deeper cannot find "update" one.

here scenario (tl;dr version below): have order table , orderdetail table, in diagram:

enter image description here

the orderdetail.subtotal computed column, simple fomula: ([price]*[quantity])

the order.total computed column, formula: ([dbo].[calculateordertotal]([id])), , here function:

alter function [dbo].[calculateordertotal] (     @orderid int ) returns int begin     declare @result int;      select @result = sum(od.subtotal)     orderdetail od     od.orderid = @orderid;      return @result; end 

tl;dr: order , orderdetail updated, inserting. need query usually, though not inserting. if check subtotal , total persist, since of operations won't affect subtotal field of row, sql server know database need update affected record, or have recompute record of order table? or bad?

p.s: using sql server 2008 in case matters.

computed columns calculated when selected.
persisted columns calculated when expressions calculated changed.
select performance suggest using persist, storage space not use persist, since "regular" computed columns not stored in database.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -