每天执行一次查询

编程入门 行业动态 更新时间:2024-10-28 17:16:23
本文介绍了每天执行一次查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

基本上,我有一个 MySQL 数据库,该数据库带有一个表,用于存储来自我的网站用户的请求.我想自动执行一个查询,该查询会基于列删除所有早于180天的已完成请求(已完成表示状态 Status = 3 ).

Basically I have a MySQL database with a table that stores requests from the users of my website. I would like to automatically perform a query that removes all completed requests (completed means that the column Status = 3) older than 180 days basing on the column ArchivingDate.

我的请求表:

My Requests table:

Requests( RequestID INT AUTO_INCREMENT PRIMARY KEY, Ticket VARCHAR(40) NOT NULL UNIQUE, RequestDate DATETIME NOT NULL, ReplacementOrRefund INT NOT NULL, ItemName VARCHAR(200) NOT NULL, Total NUMERIC(15, 2) NOT NULL, AccountName VARCHAR(200) NOT NULL, Email VARCHAR(254) NOT NULL, BillingAddress VARCHAR(200) NOT NULL, OrderNumber VARCHAR(50) NOT NULL, OrderDate DATETIME NOT NULL, DeliveryDate DATETIME NOT NULL, WhoSigned VARCHAR(200), WhereLeft VARCHAR(200), Status INT NOT NULL, ArchivingDate DATETIME, PayPalTransactionID VARCHAR(100), Toggle TINYINT(1) NOT NULL, StoreID_FK INT, FOREIGN KEY (StoreID_FK) REFERENCES Stores(StoreID) );

我已经编写了查询以删除超过180天的行:

I have already written the query to remove rows that are older than 180 days:

$ remove =更新请求SET Toggle = 0,状态= 3 AND ArchivingDate< DATE_SUB(NOW(),间隔180天)";

注意::我不从表中删除数据,我只是通过将列 Toggle 设置为来隐藏"它0 .

NOTE: I do not remove data from the table, I simply "hide" it by setting the column Toggle to 0.

问题::如何自动使MySQL每天执行一次此查询(如果可能的话)?

Question: How do I automatically make MySQL perform this query once a day (if it's possible)?

非常感谢您!

推荐答案

是的,请参阅此文章: www.sitepoint/how-to-create-mysql-events/

yes, it's possible, see this article: www.sitepoint/how-to-create-mysql-events/

更多推荐

每天执行一次查询

本文发布于:2023-10-26 08:13:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529600.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!