I want to generate the next
enroll_no. It is incremented by group for each
institute_id and every new institute has to start
enroll_no at 1. When an institute has multiple branches then the problem happens.
If we fetch
MAX(enroll_no) and then increment 1 and insert and at the same time branch 2 fetches the same
MAX(enroll_no), then after incrementing they both send same enroll_no to the server. This creates a duplicate enroll_no for the institute_id.
I need them to be exclusive and possibly use a lock there but i don't know how to go about that.