set global event_scheduler = 1;

CREATE EVENT mazani_jmen
  ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP (CURDATE(),'23:50:00')
 DO
    delete z.* from uzivatel z left join rezervace r on z.id_uzivatele=r.id_uzivatele where r.id_uzivatele is null and opravneni='ne';

CREATE EVENT mazani_archiv_obdobi
  ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP (CURDATE(),'23:50:00')
 DO
delete o.* from archiv_obdobi o left join archiv_strava_v_obdobi v on v.id_obdobi=o.id_obdobi where v.id_obdobi is null

CREATE EVENT mazani_archiv_cenik_sluzeb
  ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP (CURDATE(),'23:50:00')
 DO
delete c.* from archiv_cenik_sluzeb c left join archiv_strava_v_obdobi v on v.id_strava_v_obdobi=c.id_strava_v_obdobi where v.id_strava_v_obdobi is null



CREATE EVENT mazani_strava_v_obdobi
  ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP (CURDATE(),'23:53:00')
 DO
delete v.* from strava_v_obdobi v left join obdobi o on v.id_obdobi=o.id_obdobi where o.id_obdobi is null


CREATE EVENT mazani_archiv_strava_v_obdobi
  ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP (CURDATE(),'23:54:00')
 DO
delete v.* from archiv_strava_v_obdobi v left join archiv_obdobi o on v.id_obdobi=o.id_obdobi where o.id_obdobi is null




CREATE EVENT presun_rezervaci
  ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP (CURDATE(),'23:55:00')
 DO
delete r.*  from rezervace r, detail_rezervace d, cenik_sluzeb c, strava_v_obdobi s, obdobi o  where r.id_rezervace = d. id_rezervace and c.id_sluzby=d.id_sluzby and c.id_strava_v_obdobi=s.id_strava_v_obdobi and s.id_obdobi=o.id_obdobi and o.datumplatdo=CURDATE(); 

CREATE EVENT presun_detailu
  ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP (CURDATE(),'23:56:00')
 DO
delete d.*  from detail_rezervace d, cenik_sluzeb c, strava_v_obdobi s, obdobi o  where c.id_sluzby=d.id_sluzby and c.id_strava_v_obdobi=s.id_strava_v_obdobi and s.id_obdobi=o.id_obdobi and o.datumplatdo=CURDATE(); 

CREATE EVENT presun_cenik
  ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP (CURDATE(),'23:57:00')
 DO
delete c.*  from cenik_sluzeb c, strava_v_obdobi s, obdobi o  where c.id_strava_v_obdobi=s.id_strava_v_obdobi and s.id_obdobi=o.id_obdobi and o.datumplatdo=CURDATE(); 

CREATE EVENT presun_strava
  ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP (CURDATE(),'23:58:00')
 DO
delete s.*  from strava_v_obdobi s, obdobi o  where s.id_obdobi=o.id_obdobi and o.datumplatdo=CURDATE(); 

CREATE EVENT presun_obdobi
  ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP (CURDATE(),'23:59:00')
 DO
delete o.*  from obdobi o  where o.datumplatdo=CURDATE(); 
