插入到同一表中触发mysql [英] Insert into same table trigger mysql

查看:60
本文介绍了插入到同一表中触发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.

这篇关于插入到同一表中触发mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆