Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DELIMITER $$
DROP PROCEDURE IF EXISTS duplicate_rows$$
CREATE PROCEDURE duplicate_rows (IN tablename VARCHAR(255), IN times INT)
BEGIN
SET @statement = CONCAT(CONCAT(CONCAT(CONCAT("INSERT INTO ",tablename)," SELECT * FROM "),tablename),";");
PREPARE stmt FROM @statement;
WHILE times > 0 DO
SELECT times as "Remaining";
EXECUTE stmt;
SET times = times - 1;
END WHILE;
DEALLOCATE PREPARE stmt;
END
$$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment