Sql-server – When are computed columns computed

computed-columnsql server

When are the values for computed columns determined?

  • When the value is retrieved?
  • When the value is changed?
  • Some other time?

I'm guessing this is a novice question since I'm not finding anything in my searches.

Best Answer

It depends on how you define the computed column. A PERSISTED computed column will be calculated and then stored as data inside the table. If you do not define the column as PERSISTED, it will be calculated when your query is run.

Please see Aaron's answer for a great explanation and proof.

Pinal Dave also describes this in detail and shows proof of storage in his series:

SQL SERVER – Computed Column – PERSISTED and Storage