.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Articles >> DataBase >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Calculated Columns in Sql Server

Posted By:Deco       Posted Date: September 20, 2010    Points: 5    Category: DataBase    URL: http://www.dotnetspark.com  

Calculated Columns in Sql Server 2005

A calculated column is a powerful feature where it represent the predefined expression

like a view does. Like a view, The calculated column does not store any value actually,

 instead, the data is calculated only when a query is executed.

it helps in maintaining data integrity by doing calculations at the table level rather than

 having the hope that each and every developer would get the calculations correct.

They can even be indexed.

The syntax is opposite to that of the column alias;

ColumnName as Expression

The Employee table from the Database "adsingh" has a calculated column for the extended

salary as shown in the following code

CREATE TABLE dbo.EmployeeDetail(


DaysWorked INT,

DaySalary INT,

MonthlySalary AS DaysWorked * DaySalary Persisted





Calculated Column will be persisted on the disk with Sql Server 2005.

This will most importantly improves the performance in the calculated column

when a search is done.


 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend