CREATE PROCEDURE `spDeleteStudent` ( IN `P_StudentId` INTEGER , IN `P_BatchId` INTEGER , IN `P_InstituteId` INTEGER ) BEGIN IF ( `P_BatchId` = ? ) THEN IF EXISTS ( SELECT ? FROM `tstudent` , `tbatch` , `tinstitute` WHERE `tstudent` . `Id` = `P_StudentId` AND `tinstitute` . `Id` = `P_InstituteId` ) THEN START TRANSACTION ; DELETE FROM `tstudent` WHERE `tstudent` . `Id` = `P_StudentId` ; CALL `spUnassignBatch` ( `P_BatchId` , `P_StudentId` ) ; SELECT ? ; COMMIT ; ELSE SELECT ? ; END IF ; ELSE IF EXISTS ( SELECT ? FROM `tstudent` , `tbatch` , `tinstitute` WHERE `tstudent` . `Id` = `P_StudentId` AND `tbatch` . `Id` = `P_BatchId` AND `tinstitute` . `Id` = `P_InstituteId` ) THEN CALL `spUnassignBatch` ( `P_BatchId` , `P_StudentId` ) ; ELSE SELECT ? ; END IF ; END IF ; END 