CREATE PROCEDURE `spDeleteETestQuestions` ( IN `P_QuestionId` INTEGER ) BEGIN DECLARE `QuestionPath` VARCHARACTER (?) DEFAULT ? ; START TRANSACTION ; IF NOT EXISTS ( SELECT ? FROM `tetestquestions` WHERE `Id` = `P_QuestionId` AND `IsSubmitted` = ? ) THEN SET `QuestionPath` = ( SELECT `Filepath` FROM `tetestquestions` WHERE `Id` = `P_QuestionId` ) ; DELETE `tqo` FROM `tetestquestionoptions` `tqo` WHERE `tqo` . `QuestionId` = `P_QuestionId` ; DELETE `ttq` FROM `tetestquestions` `ttq` WHERE `ttq` . `Id` = `P_QuestionId` ; SELECT `QuestionPath` ; ELSE SELECT ? ; END IF ; COMMIT ; END 