Click here to Skip to main content
16,016,570 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"

SQL
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

1 solution

Cursor will be as follows..

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900