Let’s say that we have one table with a field called sales_total and another table with a bunch of sales entries. Let’s also, for a moment, imagine that it is impractical to count the entries every time we want to see the total number of sales.
Is it possible to have MySQL automatically update the sales_total field every time the number of sales entries changes?
I know that you can do this by running another query via C#, PHP or whatever – I’m just curious whether MySQL (or some other database system) can do this within itself?
P.S. This is of course a pretty banal example – the ideal solution should be able to handle more complex operations (storing several rows as a string in a field, etc).
use mysql trigger…
trigger on update from the first table should have some queries to update the second table.