Creating a Computed Column

A computed column is a column whose content is computed from values in other columns in the table. Computed columns are not available in all DBMSs.

Simple computed expressions can be entered directly in the Computed expression field on the Detail tab of the column property sheet. For more complex expressions, click the Edit tool to the right of the field to access the SQL Editor (see Writing SQL Code in the PowerDesigner SQL Editor).

In the following example a column must be filled with the total sales of widgets computed by multiplying the number of widgets by the widget price:

Column name

Contents

Action on data

Number of widgets

Number of widgets sold

Widget price

Price of widgets when sold

Widget sales

Total widget sales

Computed by multiplying the first two columns

  1. Open the table property sheet and click the Columns tab.
  2. Click the Add a Row tool, and then click the Properties tool to open the property sheet for the new column.
  3. On the General tab, select the Computed checkbox, and then click the Detail tab.
  4. Click the Edit tool to the right of the Computed Expression field to open the SQL Editor and enter the appropriate expression to compute the values for the column.


    In our example, we use the asterisk (*) as an arithmetic operator to multiply the number of widgets by their price.

  5. Click OK to return to the column property sheet.

    The expression is displayed in the Computed Expression pane.