Wednesday, July 24, 2019

computed columns in T-SQL

These are a thing. In SSMS, you may expand a table under "Tables" under your database and look at the "Columns" beneath the table. It will list "Computed" as a column's type in the case of a computed column. If you right-click on it and pick "Modify" and then expand "Computed Column Specification" under "Column Properties" you will see the "(Formula)" setting although I do not think there is much to change here. This sort of suggests you have to drop a computed column and readd it to make changes like so:

  1. ALTER TABLE MyTestTable
       DROP COLUMN MycomputedColumn
  2. ALTER TABLE MyTestTable
       ADD MyComputedColumn AS ( A + '-' + B + '-' + C )

No comments:

Post a Comment