Re: Stored procedure that safely increments a column

From: Tony Mountifield <tony_at_mountifield.org>
Date: Tue, 23 Jul 2019 22:24:15 +0000 (UTC)
Message-ID: <qh81ef$8ek$1_at_softins.softins.co.uk>


In article <75641124-9c96-42cb-bfcb-31eafc8297e8_at_googlegroups.com>,  <vjp1610_at_gmail.com> wrote:
> How to run this procedure to get an incremented number

Here is one possibility:

CREATE TABLE seq (num BIGINT UNSIGNED);

INSERT INTO seq VALUES(0);

Then for each time you need a new sequence number:

UPDATE seq SET num=(_at_n := num+1);

And use _at_n in the SQL statement that wants the sequence number. (SELECT _at_n; will display it)

Cheers
Tony

-- 
Tony Mountifield
Work: tony_at_softins.co.uk - http://www.softins.co.uk
Play: tony_at_mountifield.org - http://tony.mountifield.org
Received on Wed Jul 24 2019 - 00:24:15 CEST

Original text of this message