Computed columns

A computed column holds values that a SQL script calculates. Give a column a script in the CC cell of a table's Columns step, and choose whether its values are calculated at query time or at insert time.

Give a column a script

  1. Open the table and go to its Columns step. The step and its grid are covered on Edit a table's columns.
  2. Click the checkbox in the column's CC (Computed Column) cell. The script editor opens; a column that already has a script shows the checkbox ticked.
  3. Pick the type: Alias (the default) or Materialized.
  4. Type the script. The placeholder reads SQL Script e.g. "Some Other Column" * 100.
  5. Click Save. The button is enabled only once the script or the type changed.
Note

Setting a script resets the column's foreign key (FK), its mandatory flag (M) and its Default Value.

The editor stores the script on the column; the change is saved with the table's other column changes when the step is saved, the same as every other cell in the grid.

Choose between Alias and Materialized

TypeWhat it means
Alias (the default)"Calculated at query time, not stored."
Materialized"Calculated at insert time, stored in the table."

Switching the type is a change of its own: Save is enabled for it even when the script stays the same.

Clear a script

Empty the script and click Save: saving with an empty script clears the computed type. The Clear button empties the script and stays disabled while there is nothing saved or typed.

Questions, answered

What is a computed column?

It is a column whose values a SQL script calculates. In a table's Columns step it sits in the CC (Computed Column) cell: click the checkbox there to open the script editor and set the script.

What is the difference between Alias and Materialized?

Alias is the default: "Calculated at query time, not stored." Materialized keeps its values in the table: "Calculated at insert time, stored in the table." You can switch the type at any time; Save stores it.

Why is Save disabled in the script editor?

It enables only when the script or the type changed, so it stays off until you type a script or switch between Alias and Materialized.

How do I stop a column being computed?

Empty the script and click Save: saving with an empty script clears the computed type. Clear empties the script and is disabled while there is nothing saved or typed.

What happens to the column's foreign key, M flag and Default Value when I set a script?

Setting a script resets all three on the column. How the grid treats these flags on a computed column is on The table columns grid.

What does the tick in the CC cell mean?

The column has a script. The checkbox shows whether one is set: it is ticked when a script exists. Click it to open the editor and change the script.

How do I change a script I set earlier?

Click the CC checkbox to open the editor again, change the script or the type, and click Save.

Do script changes save right away?

The editor's Save stores the script on the column; the column change itself is saved with the rest of the columns when you save the step, like every other column edit. See Edit a table's columns.