Wednesday, April 4, 2018

Virtual Column in database


Virtual column value automatically calculated using a deterministic expression, in particular from the values of other fields in the table.

How to create  virtual columns

create table virtualcolumntest(
   name varchar(225),
   fixedSalery int,
   bonus int,
   totalSalery int generated always as (fixedSalery+bonus) virtual
);

Insert Values to table

In this scenario don't need to add values to the virtual column. It automatically generates.


insert into  virtualcolumntest(name , fixedSalery ,bonus) 
values ("teck4world", 20000,30000);

Then you can see table as bellow

name             fixedSalery    bonus      totalSalery
-------             --------------     --------       --------------
teck4world     20000           30000       50000


totalSalery value automatically inserted. 







No comments:

Post a Comment