0

我的数据库中有 3 个表,tbl_events、tbl_exceptions、tbl_archived_events

tbl_events存储事件列表,其中包含以下字段

**eventID** => int(4)Key, AutoIncrement
eventREF => VARCHAR (4) ( will remain the same for each version of the event and will be used to check for an exception)  
eventName => VARCHAR (30) (Name of the event)
eventType => int(4) will determine the type of event it is
eventLocation => VARCHAR (30) hold the event location data
eventDate => DATETIME hold the date of the event
eventStart => DATETIME hold the start time of the event
eventEnd => DATETIME hold the end time of the event
isReoccuring => int(2) Default to 1 which means it is reoccurring 
frequency => VARCHAR (10) will be either Daily/Weekly/Monthly/Yearly
eventLink => VARCHAR (30) will contain a link to the event page if there is one
eventValid => int(2) Will be set to 1 if the event is on and 0 if there is an exception

tbl_exceptions存储一组事件及其不举行的日期。有时可能不会举行重复性事件。该表将包含以下字段信息

**exceptionID** KeyField, AutoIncrement => int(4)
eventREF => VARCHAR (4) Holds the event ref number
exceptionDate => DATETIME , Hold the date of the exception

tbl_archive_events将存储已过期的过去事件。此表将存储与 tbl_events 表相同的数据,但仅用于过去的事件

**eventID** => int(4)Key, AutoIncrement
eventREF => VARCHAR (4) ( will remain the same for each version of the event and will be used to check for an exception)  
eventName => VARCHAR (30) (Name of the event)
eventType => int(4) will determine the type of event it is
eventLocation => VARCHAR (30) hold the event location data
eventDate => DATETIME hold the date of the event
eventStart => DATETIME hold the start time of the event
eventEnd => DATETIME hold the end time of the event
isReoccuring => int(2) Default to 1 which means it is reoccurring 
frequency => VARCHAR (10) will be either Daily/Weekly/Monthly/Yearly
eventLink => VARCHAR (30) will contain a link to the event page if there is one
eventValid => int(2) Will be set to 1 if the event is on and 0 if there is an exception[/CODE]

因此,一旦事件过期,我希望 mysql 执行以下操作:

  • 1/ 如果该事件是重复发生的事件,则创建一个新事件并将 eventDate 日期设置为相对于在频繁字段中指定的相对于现有事件的时间长度。
  • 2/ 如果在 eventException 表中找到新事件 eventREF,则将 eventValid 设置为 0
  • 3/ 一旦事件过期,将事件复制到 eventsArchive 表
  • 4/ 从 tbl_events 表中删除过期事件

到目前为止我有这个

DELIMITER $$
CREATE 
EVENT `new_event` 
ON SCHEDULE EVERY 1 DAY STARTS '2016-07-24 03:00:00' 
DO BEGIN

       -- create new event
       SELECT eventID, eventREF, eventTitle, eventLocation, eventDate, eventStart, eventEnd, isReoccuring, frequency, eventType, eventLink, eventValid
       FROM tbl_events
       WHERE eventDate < now()

       --- for each event found create a new event
       INSERT INTO tbl_events (eventID, eventREF, eventTitle, eventLocation, eventDate, eventStart, eventEnd, isReoccuring, frequency, eventType, eventLink, eventValid) 


       -- copy expired events to tbl_archived_events
       INSERT INTO tbh_archived_events (eventID, eventREF, eventTitle, eventLocation, eventDate, eventStart, eventEnd, isReoccuring, frequency, eventType, eventLink, eventValid) 
       SELECT eventID, eventREF, eventTitle, eventLocation, eventDate, eventStart, eventEnd, isReoccuring, frequency, eventType, eventLink, eventValid
       FROM tbl_events
       WHERE eventDate < now();

       -- delete expired events from tbl_events
       DELETE FROM tbl_events WHERE eventDate < now();

END */$$[/PHP]

显然以上是不正确的,我不确定我在做什么,希望能得到一些帮助谢谢

卢克

4

1 回答 1

1

您可以使用 mysql 调度程序每 5 秒或每 1 天运行一次。

http://dev.mysql.com/doc/refman/5.1/en/create-event.html

没人用这个东西



每隔1天(第二天)按计划创建事件你的事件,请
务必
调用 YOURSTROREPROCEDURE();


单独创建您的 SP

于 2016-10-20T21:23:48.937 回答