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

查看:37
本文介绍了插入同一个表触发器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天全站免登陆