【发布时间】:2015-02-27 04:44:09
【问题描述】:
我将一个程序化的交付插入到 sql 中,这是一个由以下组成的表: 最佳解决方案:
-programmed_id int
-interval int //以天为单位或更易于使用
-quantity float
-product int aforegin key
我想创建三个在插入时运行的触发器,以便它们创建一个在每个时间间隔(在新行中指定)运行的事件,以更新产品设置 products.quantity=products.quantity -programmed_delivery.quantity where products。 id=产品
我需要第二个触发器来删除事件并在更新时使用新变量重新创建它
删除时我只有一个问题,如何根据删除的行知道要删除的事件?
问题是我刚刚意识到您无法在触发器中处理事件。有人知道解决方法吗?也许是一个php解决方案?有什么建议吗?
非常感谢您的帮助。
过了一会儿……
这行得通吗?作为做我想做的事的测试
每天打折送货
创建数据库prueba; 使用普鲁巴; 创建表 t1(id_producto int(11) not null auto_increment,quantity int(11) not null,primary key(id_producto)); 创建表 t2(id_delivery int(11) not null auto_increment,id_producto int(11) not null,quantity int(11) not null,fecha date not null default '2014-12-11',主键(id_delivery)); 插入 t1(数量)值(5),(6),(8); 插入 t2(id_producto,quantity,fecha) 值(1,1,curdate()),(2,2,curdate()),(1,2,curdate()); 创建事件 如果不存在按计划每 1 天交付一次,请更新 t1 内部连接(从 t2 选择 id_producto 作为 id,数量从 t2 where fecha=curdate())作为 t22 on t22.id=t1.id_producto 设置 t1.quantity=t1.quantity -t22.quantity 其中 t1.id_producto>0;
【问题讨论】:
-
看起来像XY problem。清楚地解释你的最终目标是什么。 “程序化交付”是什么意思?
-
是一种每月都会完成的交货,这意味着我们每 x 时间发送一次产品,因此我们每 x 时间从库存中打折,并且用户必须能够使用插入或创建新程序化交付的界面
-
如果理解正确,则运行一项 cron 作业或处理当天所有交付的事件。
-
现在这是个好主意。您能否发布一些代码,以便我给您答案。一方面,我不知道如何使用 cron 作业。
-
这个活动有效吗??