user2827435 user2827435 - 9 days ago 5
SQL Question

How to increase the MySQL variable count

Friends, in my project I have a variable named bill_number; every time the PRINT bill button is clicked I want to increase the value of bill_number by one in the database. Please help me as soon as possible.

set @bill_number = @bill_numer+1;


This is the query I've tried before but it's not working.

Answer

I would advise to maintain a table containing all the counts (like bill_number) and then use SELECT FOR UPDATE to fetch and update the count on the events. It will increase the maintainability.

Comments