Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Instance Stored Procedure call

Is there any way that I can make sure that a stored procedure completely finishes before another instance of it is started?

I have to do 3 things in the procedure and if two instances are running at the same time it will mess up a boundary case.

Example: Count rows, if < X insert a row, return calculated Y

if multiple instances of the stored proc can run at the same time I could go past my X target. Chance is small, but its there.

DB we're using is MYSQL5, but also wondering for MSSQL

like image 306
Dilbert789 Avatar asked Aug 31 '26 06:08

Dilbert789


1 Answers

Use transactions. Check row count afterwards and roll back if it's gone over.

like image 144
Anon. Avatar answered Sep 01 '26 19:09

Anon.