Search code examples
sqlsql-serversql-server-2008persisted-column

Can a PERSISTED column reference an existing persisted field?


Can persisted column reference another persisted column and are there any rules to this such as do they calculate the persisted fields sequentially or at least calculate the ones that are referenced by other columns first?


Solution

  • No, computed columns can't reference other computed columns. just repeat the expression that you want to reference.

    There is no left to right order of evaluation here. e.g.

      CREATE TABLE T
      (
      B AS A*2 PERSISTED,
      A INT
      )
    

    Works fine even though the computed column B references A which appears after it.