Sample Header Ad - 728x90

Delete from table in chunks

2 votes
5 answers
18933 views
I want to cleanup one of my tables which has 4 million. So I prepare this query to clean it. But it's throwing an error, can anyone please help me to fix this? DELIMITER $$ DROP PROCEDURE IF EXISTS archive_table $$ create procedure archive_table () set @min=(select min(dob) from test where dob @min and dob < DATE_SUB(CURDATE(), INTERVAL 30 day) ); END WHILE; END$$ **ERROR:** ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'while @min is not null begin delete from test where dob = @min; commi' at line 1
Asked by TheDataGuy (1986 rep)
Oct 27, 2017, 04:55 PM
Last activity: Oct 30, 2022, 08:11 PM