mysql
自增ID
select last_insert_id()
自增ID独一无二
The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function to a given client is the first AUTO_INCREMENT value generated for most recent statement affecting an AUTO_INCREMENT column by that client. This value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that each client can retrieve its own ID without concern for the activity of other clients, and without the need for locks or transactions. —— Mysql5.6 官方文档
Mysql服务器每个connection都会维护自己的自增ID,∴各个事务之间对AUTO_INCREMENT的字段修改是互不干涉的,这也使得在各个事务各自操作时,无需担忧锁的需求或者事务的需求etc。
一次插入多个值
insert into table_test values(),();
对于这种情况,服务器仅返回插入的第一行的自增ID。
一次插入两张表
比如先A表再到b表,这样子的话记录的是B表中的数据