Insert into same table trigger mysql

后端 未结 4 1334
眼角桃花
眼角桃花 2020-12-12 03:35

I need to insert a discount line into a table everything time a I insert a line into the same table. Now i know that this could end in a endless loop but I have put checks i

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 03:52

    Why don't you just change your INSERT code into something like this? :

    INSERT INTO table1 (field1, field2, ...) 
    VALUES ( @item, @price, ....)
         , ( @item, @discount, ...) ;
    

    Another thing would be to re-evaluate your data structure. The way it is now, it seems - from the limited information you have provided - that it's not normalized. You are storing two types of info in the table.

    Perhaps you can combine the two rows (that are to be inserted every time) into one, by adding a few columns in the table.

    Or by splitting the table into two tables, one for the "normal" item rows and one for the discount items.

提交回复
热议问题