我创建了一个表,我需要将每个条目的自动增量切换为+2。我找到了一种在全局范围内做到这一点的方法:
setting auto increment=2
auto increment offset=2
我可以只对一张 table 执行此操作吗?
最佳答案
auto_increment_offset只会设置所有表格的起点,而不是增量。
表定义或 alter 语句中的 AUTO_INCRMENT 将为该单个表设置起始 auto_increment 编号。
您正在寻找的更像是 server setting auto_increment_increment 。不幸的是,MySQL 中的单个表不支持这一点。引用手册:
您可以尝试滚动自己的序列,有一个单独的 auto_increment“序列”表,每次插入该表时都会插入该表,只需从序列表中取出last_insert_id()并将其乘以2即可用于其他表使用。
关于mysql - 特定表自动递增 2(无 php 处理),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21412139/