×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: SQL
Posted by: Roman Ignatov
Added: Nov 30, 2016 11:12 AM
Views: 11
Tags: mysql sysadmin
  1. -- простой вариант
  2. DELETE FROM logs WHERE TIME < DATE_ADD(NOW(), INTERVAL -7 DAY);
  3.  
  4.  
  5. -- надо проверить как это будет работать
  6.  
  7. CREATE TRIGGER clean_logs AFTER INSERT ON logsTable
  8. FOR EACH ROW
  9. BEGIN
  10.  
  11. DELETE FROM logs WHERE TIME < DATE_ADD(NOW(), INTERVAL -7 DAY);
  12.  
  13.  
  14.  
  15. END;
  16.  
  17.  
  18. -- через евенты
  19.  
  20. CREATE EVENT cleanLogs
  21. ON SCHEDULE EVERY 1 DAY
  22. DO DELETE FROM logs WHERE TIME < DATE_ADD(NOW(), INTERVAL -30 DAY);
  23.  
  24.  
  25.  
  26. -- из доки
  27.  
  28. -- "EVERY interval" means "Do this repeatedly". A recurring interval starts with EVERY, -- -- followed by a positive integer plus one of the keywords
  29. -- YEAR, MONTH, WEEK, DAY, HOUR, MINUTE, or SECOND.