Databases Reference
In-Depth Information
In step 11 we drop the
MAX_CREDIT
column and the trigger used to set its value, and in step
12 we re-create the
MAX_CREDIT
field, defining it as a virtual column. Here, we specify the
formula evaluated to implement the same fanciful business rule as implemented earlier in
the trigger.
In step 13 we execute the same insert statement as in step 10. In the following screenshot
the output of this operation can be observed. Then in step 14 we drop the
MY_CUSTOMERS
table to clear the
SH
database schema.
In this example you can see that the insert statement with the virtual column needs half the
time required by the insert on the same table, when the
MAX_CREDIT
field value is calculated
using a trigger. The benefit in performance will vary due to the different amount of work
needed in the trigger execution.
There's more...
In previous recipes we have encouraged the use of indexes to increase the execution speed
of our queries.