mysql 一次插入多条数据,能否取得lastId?

可以。使用 LAST_INSERT_ID() 函数仍然正常返回最后一个ID。

实例:

INSERT INTO `public_up`(`uid`, `tid`, `ruid`, `action`, `module`, `puctime`, `type`, `isread`) VALUES (11436, 595, 1450, 'detail', 'article', 1550627754, 0, 0),(11436, 595, 1450, 'detail', 'article', 1550627754, 0, 0),(11436, 595, 1450, 'detail', 'article', 1550627754, 0, 0),(11436, 595, 1450, 'detail', 'article', 1550627754, 0, 0);


SELECT LAST_INSERT_ID() as lastID;  // 返回批量插入的最后一个 ID

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注