插入同一张表触发mysql

Insert into same table trigger mysql(插入同一张表触发mysql)
本文介绍了插入同一张表触发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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)