Skip to content

Instantly share code, notes, and snippets.

@ivanweiler
Last active October 23, 2019 14:23
Show Gist options
  • Save ivanweiler/d119a84da790ea2a5cff80db113777b0 to your computer and use it in GitHub Desktop.
Save ivanweiler/d119a84da790ea2a5cff80db113777b0 to your computer and use it in GitHub Desktop.
DROP PROCEDURE IF EXISTS ClearCoreUrlTable;
DELIMITER $$
CREATE PROCEDURE `ClearCoreUrlTable`()
BEGIN
SET @delete_counter = 0;
SET @table_name = 'core_url_rewrite';
SET @total_records = (SELECT count(*) FROM core_url_rewrite WHERE product_id is not null and category_id is not null);
WHILE @delete_counter < @total_records DO
SET @varSQL = CONCAT('DELETE FROM ', @table_name,' WHERE category_id IS NOT NULL and product_id IS NOT NULL AND is_system=0 LIMIT 500;');
PREPARE stmt FROM @varSQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @delete_counter = @delete_counter + 500;
END WHILE;
END $$
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment