DROP PROCEDURE IF EXISTS p_DropIdx;
GO
CREATE PROCEDURE p_DropIdx
(
	IdxName VARCHAR(50),
	TableName VARCHAR(50)
) SQL SECURITY INVOKER
BEGIN
	DECLARE
	 oldIdxName VARCHAR(30);

	IF EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = SCHEMA() AND TABLE_NAME = TableName AND INDEX_NAME = IdxName) THEN
		SET @sqlcounts = concat( 'DROP INDEX ', IdxName, ' ON ', TableName);
		PREPARE stmt
		FROM
		 @sqlcounts;
		EXECUTE stmt;
		DEALLOCATE PREPARE stmt;
	END IF;
END;
GO
