|
An expression used on a column is a combination of
operators and operands used to produce the value of the column. The user
will not enter a value for such a column.
To visually specify an expression for a column,
display the table in Design View. In the top section, enter or select the
column name. In the bottom section, expand the Computed Column
Specification field and, in its (Formula) field, enter the desired
expression. Here is an example:
|
To create an expression in SQL, in the placeholder of the
column, enter the name of the column, followed by AS, and followed by the
desired expression. Here is an example:
CREATE TABLE Circle
(
CircleID int identity(1,1) NOT NULL,
Radius decimal(8, 3) NOT NULL,
Area AS Radius * Radius * PI()
);
GO
When performing data entry, you must not provide a
value for a column that has an expression; the SQL interpreter would
provide the value automatically. Here is an example of entering data for
the above Circle table:
INSERT INTO Circle(Radius) VALUES(46.82);
GO
INSERT INTO Circle(Radius) VALUES(8.15);
GO
INSERT INTO Circle(Radius) VALUES(122.57);
GO