MySQL Forums
Forum List  »  Newbie

Re: How to delete millions of record in a loop
Posted by: Barry Galbraith
Date: November 16, 2016 06:11PM

` is back tick, and is used to allow you to use reserved words as identifiers. You save yourself a LOT of heartache if you DON'T use reserved words as identifiers.
' is a quote mark and is used to surround a string.

When you want to write a stored procedure, it usually contains several statements.
So you can send ALL of them to mysql without being interpreted, and acted on, you need to change the delimiter from the usual ; to something else that wouldn't normally appear in SQL, like //

So, to write a SP, you need to change the delimiter,

mysql>DELIMITER //

write your multiple SQL statements, and mysql will not see ; as terminating input

CREATE PROCEDURE delete_table_incrementally
MODIFIES SQL DATA
BEGIN
REPEAT
DELETE FROM mytable;
LIMIT 3;
UNTIL ROW_COUNT() = 0
END REPEAT;
END;

send the delimiter, so mysql knows you've finished,

//

and then change the delimiter back to normal

DELIMITER ;


But all of that isn't the issue here.
Like Phillip says, why can't you just TRUNCATE your table?

Good luck,
Barry.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.