Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when the computed column will update?

I have computed column in table called "Claim" and definition of column is calling one scalar function.

I created a 10000 claims so when i select those 10000 claims the computed column will update are when 10000 rows inserting itself the computed column will execute?

Please update me

Thanks in advance

like image 585
VInayK Avatar asked Mar 16 '11 16:03

VInayK


People also ask

Can we update computed column in SQL Server?

If we update the records in the SQL table, and computed columns calculate updated value once we retrieve data again. However, we cannot update or insert values in the virtual computed columns in SQL Server.

What is the purpose of a computed column?

A computed column is a virtual column that is not physically stored in the table, unless the column is marked PERSISTED. A computed column expression can use data from other columns to calculate a value for the column to which it belongs.

How can I tell which column is updated?

Solution. Using a SQL Server trigger to check if a column is updated, there are two ways this can be done; one is to use the function update(<col name>) and the other is to use columns_updated().

How do you check if computed column is persisted?

A persisted computed column is one that is physically stored in the table. If you don't specify that it's persisted, then the column's value will be calculated each time you run a query against it. You can query the sys. computed_columns system catalog view to find out whether a computed column is marked as persisted.


2 Answers

It depends if the computed column is marked as persisted or is indexed.

If neither of these conditions are true then nothing is stored and it is calculated at runtime. Otherwise it is automatcally updated when the underlying data changes.

like image 190
Martin Smith Avatar answered Oct 04 '22 00:10

Martin Smith


The computed column computes its value when you execute a SELECT command that includes the column, assuming that the computed column's value is not PERSISTED.

like image 22
Brian Driscoll Avatar answered Oct 03 '22 23:10

Brian Driscoll