Click here to Skip to main content
12,625,355 members (40,981 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: MySQL
Hi,
I had a limited database in my server, for that reason in every 6 months i need to delete old datas,
My table name is SystemEvents and i had a column ReceivedAt it stores date like "2013-01-16 13:00:01"

Create Trigger deleteData  After Delete On 'SystemEvents'
For EACH ROW
BEGIN
DELETE FROM SystemEvents
WHERE(ReceivedAt // !!!!!!!!
END


WHERE(ReceivedAt // !!!!!!!! what shoul i write here to delete the data which are older than 5 months)
Also it is the first time that i am writing a mysql trigger please check my syntax.
Posted 23-Jan-13 22:43pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Cursor will be as follows..

CREATE TRIGGER deleteData  AFTER DELETE ON SystemEvents
For EACH ROW
BEGIN
	DELETE FROM SystemEvents
	WHERE ReceivedAt < DATE_SUB(NOW(), INTERVAL 5 MONTH)
END
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 18 Mar 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100