Mysql中的自增问题 [英] Auto Increment Problem in Mysql
问题描述
我创建了一个表并设置了一个字段来自动增加这样的事情:
I created a table and set a field to auto increment some thing like this:
CREATE TABLE t1(id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE = MyISAM AUTO_INCREMENT = 123456;
但出于某种原因,我删除了表中的一些行.
But to some reason i deleted some of the rows in the table.
现在的问题是,当我在表中插入新行时,应该为新行分配已删除行的 ID,而不是分配新 ID.
Now the question is when i insert new rows in the table the new rows should be assigned id's of the rows which have been deleted rather than assigning new id's.
我不想重置所有的 id
I do not want to reset all the id's
我该怎么做??
感谢帮助:)
推荐答案
抱歉,那不是AUTO_INCREMENT的用途.
如果你想重用id的,那你就得编写自己的触发器函数,这样做通常被认为是不好的做法.
Sorry to say, but that is not the use of AUTO_INCREMENT.
If you want to re-use id's, then you would have to write your own trigger functions, and doing this is generally considered bad practice.
假设您在 ID 为 50,000 的情况下删除了一个 ID 为 1 的条目...您真的希望您添加的下一条记录重新使用 ID 1 吗?
Imagine you were on id 50,000, and deleted an entry with id 1... would you really want the next record you add to re-use id 1?
这篇关于Mysql中的自增问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!