如何插入新的自动增量ID

如何插入新的自动增量ID

问题描述:

我找到了mysql_insert_id函数来检索最后一个自动生成的ID.

I found the mysql_insert_id function to retrieve the last auto generated ID.

我应该使用mysql_insert_id +1来添加新的ID还是调用添加新的唯一ID?

Should I be using mysql_insert_id +1 to add a new ID or is there a call for adding a new unique ID?

使用NULL作为ID:

Using NULL for id:

INSERT INTO  `database`.`table` (`id`, `user`, `result`) VALUES (NULL, 'Alice', 'green')");

或者根本不指定ID:

INSERT INTO  `database`.`table` (`user`, `result`) VALUES ('Alice', 'green')");

这两种方法都可以正常工作,更多的是一种偏爱,但我个人选择第二种方法是因为它的键入较少.

Either way works just fine, more of a preference but personally I chose the second as its less typing.