Comments - How to insert only the number of data specified by mariadb?

3 years ago Daniel Black

To your `Theater (id, description)` table add a field of `remaining int default 100`.

Use transactions when making the reservation:

BEGIN
UPDATE Theater SET remaining=remaining-1 WHERE id=1 AND remaining>1
(in application code, examine ROWS_AFFECTED from this update and if not 1, ROLLBACK + no seats available
INSERT INTO Reservation ...
COMMIT
 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.