A computed column is computed from an expression that can use other columns in the same table. The expression can be a noncomputed column name, constant, function, and any combination of these connected by one or more operators.
Create table with a computed column
Create table NetProfit
(
SalaryToEmployee int,
BonusDistributed int,
BusinessRunningCost int,
BusinessMaintenanceCost int,
BusinessEarnings int,
BusinessNetIncome
As BusinessEarnings - (SalaryToEmployee +
BonusDistributed +
BusinessRunningCost +
BusinessMaintenanceCost )
)
Value is computed and stored in the computed column automatically on inserting other values.
Insert Into NetProfit
(SalaryToEmployee,
BonusDistributed,
BusinessRunningCost,
BusinessMaintenanceCost,
BusinessEarnings)
Values
(1000000,
10000,
1000000,
50000,
2500000)