Microsoft SQL Server Computed Columns A column is computed from an expression

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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)    


Got any Microsoft SQL Server Question?