Emulating a transaction-safe SEQUENCE in MySQL

后端 未结 4 2167
不思量自难忘°
不思量自难忘° 2020-12-08 23:33

We\'re using MySQL with InnoDB storage engine and transactions a lot, and we\'ve run into a problem: we need a nice way to emulate Oracle\'s SEQUENCEs in MySQL. The requirem

4条回答
  •  被撕碎了的回忆
    2020-12-09 00:20

    The right way to do this is given in the MySQL manual:

    UPDATE child_codes SET counter_field = LAST_INSERT_ID(counter_field + 1);
    SELECT LAST_INSERT_ID();
    

提交回复
热议问题