What is a computed column in SQL Server?

SQL Server Design Intermediate 2–3 Yrs3–5 Yrs Conceptual 1 min read

Quick Answer

A computed column is defined by an expression over other columns in the same row — FullName AS FirstName + ' ' + LastName. By default it's calculated on read (virtual); add PERSISTED to store it physically, which lets you index it and speeds up reads at a small write cost.

A computed column is one whose value comes from an expression on other columns in the row — like a FullName built from first and last name, or UPPER(Email) for a case-insensitive lookup. Normally it's virtual and calculated whenever you read it. If I mark it PERSISTED, it's stored physically and only recalculated when the source columns change, and then I can index it. That indexing use is the main reason I reach for one — for example, computing and indexing a value pulled out of a JSON column.

  • Virtual: no storage, computed each time it's referenced. Fine for cheap expressions.
  • PERSISTED: stored on disk, recomputed only when the inputs change. Required (along with determinism and precision rules) to put an index on it.
  • Common uses: a normalised search key (UPPER(Email)) you can index for sargable lookups; a derived total; extracting a value from a JSON column with JSON_VALUE and indexing it.
  • The expression must be deterministic to be persisted or indexed (GETDATE() isn't).