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


基础教程推荐
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 在多列上分布任意行 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01