CREATE PROCEDURE `spDeleteTeacherContent` ( IN `P_TeacherId` INTEGER , IN `P_ContentId` INTEGER , IN `P_FolderPath` VARCHARACTER (?) , IN `P_ContentTypeId` INTEGER , IN `P_AssignContent` INTEGER ) BEGIN DECLARE `P_TeacherContentId` VARCHARACTER (?) ; DECLARE `P_Path` VARCHARACTER (?) ; DECLARE `P_AssignPath` VARCHARACTER (?) ; DECLARE `P_BatchId` INTEGER ; DROP TEMPORARY TABLE IF EXISTS `T_AssignPath` ; IF `P_AssignContent` = ? THEN IF EXISTS ( SELECT ? FROM `tteachercontent` WHERE `Id` = `P_ContentId` AND `TeacherId` = `P_TeacherId` AND `P_ContentTypeId` IN (...) ) THEN IF `P_ContentTypeId` = ? THEN BEGIN START TRANSACTION ; SET `P_Path` = ( SELECT `CONCAT` ( REPLACE ( `ContentPath` , ?, ... ) , ? , `Id` , ? , `ContentTitle` , ? ) FROM `tteacherContent` WHERE `id` = `P_ContentId` ) ; CREATE TEMPORARY TABLE `T_AssignPath` AS SELECT `CONCAT` ( REPLACE ( `ContentPath` , ?, ... ) , ? , `Id` , ? , `ContentTitle` , ? ) AS `path` FROM `tteachercontentassign` WHERE `TeacherContentId` = `P_ContentId` ; DELETE FROM `tteacherContent` WHERE `Id` = `P_ContentId` OR `CONCAT` ( REPLACE ( `ContentPath` , ?, ... ) , ? ) LIKE `P_Path` ; DELETE `tteachercontentassign` FROM `tteachercontentassign` , `T_AssignPath` WHERE `TeacherContentId` = `P_ContentId` OR `CONCAT` ( REPLACE ( 