Finding the next available id in MySQL

前端 未结 15 1837
予麋鹿
予麋鹿 2020-11-29 00:50

I have to find the next available id (if there are 5 data in database, I have to get the next available insert place which is 6) in a MySQL database. How can I do that? I h

15条回答
  •  伪装坚强ぢ
    2020-11-29 01:28

    One way to do it is to set the index to be auto incrementing. Then your SQL statement simply specifies NULL and then SQL parser does the rest for you.

    INSERT INTO foo VALUES (null);
    

提交回复
热议问题