I am working with a CMS system, and using a kind of smartform am inserting fields into a table.
In these fields are the name of a product, quantity and cost.
cost and product name are taken from a products table, while quantity is input manually.
I understand this is not the best architecture, but I am limited with the system I am working with.
What I want to do, is change the value of cost after it is inserted, to quantity * cost.
What is the easiest way to do this?
If you have your hands tied so tightly that you are unable to change the table structure, then you probably won’t be able to use a trigger, but here goes anyway.
This is a sample table structure:
Create a trigger which updates the cost prior to it being inserted into the
productstable:Insert a couple of products into the table:
The cost is updated automatically: