MySQL trigger set values for NEW row and update another in the same table

后端 未结 4 1902
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 15:14

I have a table that I keep track of fees for a specific item. These fees can change over time so I have two columns (startDate, endDate) with the current set of fees always

4条回答
  •  感动是毒
    2020-12-01 15:22

    I managed to get it to work, by creating a "wrapper table" which is defined with the same fields as your target table, but by using the FEDERATED storage engine. The federated server I defined to target the same mysql server/itself, so at "localhost". The trigger I then made change a row in the wrapper table. Of course you have to be very sure what you do in the trigger, to avoid a recursive loop. Also potentially the performance isn't that good; I haven't tested performance, but it has been working for years in a production environment.

提交回复
热议问题