Share via


How to: Specify Computed Columns

You can specify an expression for a computed column in Table Designer. A computed column expression can use data from other columns to calculate a value for the column to which it belongs.

Note

A new version of Table Designer appears for databases in the SQL Server 2012 format. This topic describes the old version of Table Designer, which you use with databases in earlier formats of SQL Server.

In the new version, you can change a table definition through a graphical interface or directly in a script pane. If you use the graphical interface, the table’s definition is automatically updated in the script pane. To apply the SQL code in the script pane, choose the Update button. For more information about the new version, see How to: Create Database Objects Using Table Designer.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To specify a computed column

  1. In Server Explorer, right-click the table with columns for which you want to specify computed columns and click Open Table Definition.

    The table opens in Table Designer.

  2. Select the column for which you want to specify a computed column formula.

  3. In the Column Properties tab, expand the Computed Column Specification property.

  4. In the (Formula) child property, type the expression for this column in the grid cell to the right.

  5. Indicate whether the data is persisted by choosing Yes or No from the drop-down for the Is Persisted child property.

    Note

    If your database engine does not allow the persisting of expression results, you cannot choose Yes for the Is Persisted property.

The new computed column specification is assigned to the column in Table Designer after you click outside the grid cell or use the TAB key to move to another grid cell and changes are stored in the database when you save your changes in Table Designer.

See Also

Reference

Column Properties

Other Resources

Working with Columns

CREATE TABLE and computed column expressions