I have a query in SQL Server like this
Alter table inventory
Add totalitems as iteminstore + iteminwarehouse PERSISTED`
What is the advantage of writing the persisted
?
I have a query in SQL Server like this
Alter table inventory
Add totalitems as iteminstore + iteminwarehouse PERSISTED`
What is the advantage of writing the persisted
?
The computed value is persisted into the table, as if it were a normal column value.
If you don't have PERSISTED
, then the value is computed every time the column is accessed.
Nicely and more extensively documented in the official MSDN documentation for computed columns:
PERSISTED
Specifies that the Database Engine will physically store the computed values in the table, and update the values when any other columns on which the computed column depends are updated. Marking a computed column as PERSISTED allows an index to be created on a computed column that is deterministic, but not precise. For more information, see Indexes on Computed Columns. Any computed columns used as partitioning columns of a partitioned table must be explicitly marked PERSISTED. computed_column_expression must be deterministic when PERSISTED is specified.