如何使用触发器以及何时使用自动更新? [英] how to use trigger and when to use for auto updation?

查看:103
本文介绍了如何使用触发器以及何时使用自动更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用phpmyadmin。我有一个带有3个属性名称|价格|日期的表'产品'。我需要在date< date时将价格重置为0当前日期(cur_date)。我尝试使用更新查询在我的php页面中执行相同操作,但是其他网站也连接到同一个数据库,因此必须在所有这些页面中写入相同的更新语句。我会更喜欢单步解决方案,可以通过使用触发器,但我不知道如何使用它。可能有人请帮我查询相同的,并提到我在php部分或phpmyadmin使用触发器语句的位置?

解决方案

您可能希望重新检查触发器的作用: CREATE TRIGGER(Transact-SQL) [ ^ ]



因此,根据您的操作,触发器不是正确的工具。根据上面的建议,你真的需要一个每晚运行的工作



一些替代方案(不是最佳实践!):



    您可能希望定义一个函数并使用该函数检索该值,以便在值到期时返回0。

I am using phpmyadmin.I have a table 'product' with 3 attributes-name|price|date.I need to reset the price to 0 when date < current date(cur_date).I tried using an update query to do the same in my php page which worked,but got other websites too connected to the same db, therefore same update statement has to be written in all of these pages.I would prefer a single step solution for the same which can be done by using trigger but im unaware of how to use it.Could someone pls help me with the query for the same and mention where am i to use the trigger statement in php part or phpmyadmin?

解决方案

You may wish to re-examine what triggers do: CREATE TRIGGER (Transact-SQL)[^]

Therefore, based upon what you wish to do a trigger is not the correct tool. As per the suggestion, above, you really need a job that runs nightly

Some alternatives (not best practices!):

    You may wish to define a function and retrieve the value with the function so that it returns 0 when the value expires.


这篇关于如何使用触发器以及何时使用自动更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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