MySQL equivalent of Oracle's SEQUENCE.NEXTVAL

前端 未结 7 1382
无人及你
无人及你 2020-12-01 11:13

I need to be able to generate run a query that will return the next value of ID on the following table:

CREATE TABLE animals (
     id MEDIUMINT NOT NULL AUT         


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 11:32

    1.) create table query
    2.) Insert query
    3.) Update query
    4.) Select query for that table e.g. SELECT next_val FROM hib_sequence;
    5.) Before each select update first, like this you can achieve similar
    
    -- CREATE TABLE hib_sequence (next_val INT NOT NULL);
    -- UPDATE hib_sequence SET next_val=LAST_INSERT_ID(next_val+1);
    -- select last_insert_id();
    -- INSERT INTO hib_sequence VALUES (0);
    
    -- select next_val from hib_sequence;
    

提交回复
热议问题