插入同一张表触发mysql
每当我在同一个表中插入一行时,我都需要在表中插入一条折扣行.现在我知道这可能会以无限循环结束,但我已将支票放入,因此在插入折扣行时它不会插入任何内容.
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 in so it wont insert anything when the discount line is inserted.
Mysql 似乎不允许这样做.它甚至不会插入到表中,更不用说触发触发器了
Mysql doesnt seem to allow this.It doesnt even insert into the table let alone fire off the trigger
关于如何做到这一点的任何建议?
Any suggestions on how to do this?
推荐答案
你为什么不把你的 INSERT
代码改成这样呢?:
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.
相关文章