指定时间后删除Mysql行 [英] Remove Mysql row after specified time

查看:53
本文介绍了指定时间后删除Mysql行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个计算机预订系统,在该系统中,用户选择一台计算机并选择他将使用这台PC的时间.那时其他人无法保留此PC,我需要找到一种解决方案,如何在其时间到期后自动删除包含保留PC的所有行.谢谢您的建议.

I'm trying to create a computer reservation system, where user chooses a computer and select the time how long he will be using this PC. In that time other persons can't reserve this pc, I need to find a solution, how to automaticaly delete all rows containing reserved pc's after their time expires. Thank you for the advice.

推荐答案

这是未经测试的答案,可能只是一个建议,但我刚刚开始研究这些内容,因此也对反馈感兴趣.我仍在努力解决各种可能性和弊端,但它可能很适合您的需求.

This is an untested answer, that may only be a suggestion, but I just started looking at these, so am interested in feedback as well. i'm still working through possibilities and drawbacks, but it might well suit your need.

看看MySQL Events,有关它的文章在此处 Mysql Docs 上的官方语法.
根据文章:

Take a look at MySQL Events, an article about it is here, and official syntax at Mysql Docs.
Per the article:

事件类似于触发器.但是,而不是在运行 响应数据更改,可以安排事件运行任意数量 在特定时期内的时间.实际上,它只是一个数据库 计划工作.

An event is similar to a trigger. However, rather than running in response to a data change, events can be scheduled to run any number of times during a specific period. In effect, it’s a database-only cron job.

考虑到这一点,我将设想一个删除大于1小时的内容的程序(如果这是到期时间).此过程将在新插入时触发,以消除当时已过期的任何内容,但在每15分钟左右运行一次的情况下,以使触发器自动删除不依赖于某人否则添加保留以触发该过程.

Pondering this, I'd envision a procedure that deleted anything >1hr (if that's the expiration). This procedure would be TRIGGERED on new inserts to get rid of anything expired at that moment, but also in an event to run every 15 minutes or so so that automatic deletes by the trigger aren't dependant on somebody else adding a reservation to trigger that procedure.

这篇关于指定时间后删除Mysql行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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