I have a table:
table Event
- name
- description
- date (in format 2011-08-06 11:00:00)
- id
I need to create recurring events.
How can I best duplicate a row with mostly the same data (name, description) but change the date?
Say, if I have an event that occurs August 6th, I would like to create three more events on
– August 13, 20, 27 (every Saturday)
Also, is this something better accomplished with a mySQL query? I am guessing so because of the format the date is in…but any advice would be appreciated.
MySQLlacks a generator functionality (which would allow to create arbitrary length recordsets from scratch), so if the number of records is fixed, you could do something like that:As you can see, the query layout depends on the number of events to create, with pure
SQLthere is no way to parameterize it.You, however, can create a stored procedure and just call
INSERTin a loop: