CREATE PROCEDURE `spCreateStudent` ( IN `P_Code` VARCHARACTER (?) , IN `P_UserId` INTEGER ) BEGIN IF EXISTS ( SELECT * FROM `tstudent` WHERE `UserId` = `P_UserId` ) THEN BEGIN SELECT `P_UserId` ; END ; ELSE INSERT INTO `tstudent` ( CODE , `UserId` , `InstituteId` , `CreatedDateTime` , `UpdatedDateTime` ) VALUES ( `P_Code` , `P_UserId` , ? , NOW ( ) , NOW ( ) ) ; SELECT `LAST_INSERT_ID` ( ) ; END IF ; END 