Computed Columns
Computed columns can be defined with the COMPUTED [BY]
or GENERATED ALWAYS AS
clause (the SQL standard alternative to COMPUTED [BY]
).Specifying the data type is optional;if not specified, the appropriate type will be derived from the expression.
If the data type is explicitly specified for a calculated field, the calculation result is converted to the specified type.This means, for instance, that the result of a numeric expression could be converted to a string.
In a query that selects a computed column, the expression is evaluated for each row of the selected data.
Tip
|
Instead of a computed column, in some cases it makes sense to use a regular column whose value is calculated in triggers for adding and updating data.It may reduce the performance of inserting/updating records, but it will increase the performance of data selection. |