Thursday, 20 April 2017

Computed Column In Sql Server Part I

In this Article we will learn what is Computed Column in Sql Server.How to Declare what are the advantages using this column in Sql Server.Practical Implementation of Computation column in Sql Server.

Computed Column name it self indicates that it computes other columns values and display that result in that particular column.This column is an Virtual Column no datatype is allocated for this column in DB this column won't store data in table unless the column is marked as persisted

No Let us See How we can implement Computed Columns in Practically




Syntax for Table Creation


CREATE TABLE tblStudent (ID INT Identity,SName NVARCHAR(100),M1 INT,M2 INT,M3 INT,Tot AS (M1+M2+M3))

Here Tot is the computed column.

Syntax For Data Insertion

INSERT INTO tblStudent(SName,M1,M2,M3) Values('A',86,93,94)

Note :
        Here we Need to use Computed Column to pass data because it automatically calculates based on the existing column values.




Select *from tblStudent

Now we can check how data looks like

No comments :

Post a Comment