DROP PROCEDURE IF EXISTS sp_DropIndexOfTable;
DELIMITER $$
CREATE PROCEDURE sp_DropIndexOfTable(IN TableName VARCHAR(255))
BEGIN
	DECLARE v_finished INTEGER DEFAULT 0;
	DECLARE v_index varchar(200) DEFAULT "";
	DEClARE index_cursor CURSOR FOR
		SELECT INDEX_NAME
		FROM INFORMATION_SCHEMA.STATISTICS
		WHERE TABLE_SCHEMA = (SELECT DATABASE())
		AND TABLE_NAME = TableName
		AND INDEX_NAME != 'PRIMARY';
   DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished = 1;
   
	DECLARE exit handler FOR sqlexception
 	BEGIN
		SHOW ERRORS LIMIT 1;
		ROLLBACK;
	END;
	
	DECLARE exit handler FOR sqlwarning
	BEGIN
		SHOW WARNINGS LIMIT 1;
		ROLLBACK;
	END;
	
	OPEN index_cursor; 
	get_index: LOOP
	FETCH index_cursor INTO v_index;
	
	IF v_finished = 1 THEN
		LEAVE get_index;
	END IF;
	
	SET @v_query = CONCAT('DROP INDEX ',v_index,' ON ', TableName);
	PREPARE stmt FROM @v_query;
	EXECUTE stmt;
	DEALLOCATE PREPARE stmt;
	END LOOP get_index;
	
	CLOSE index_cursor;
END$$
DELIMITER ;