因此,我需要重置该表。我尝试使用“Truncate table”语句进行重置,但由于“该表被另一个表的外键约束引用”,所以它失败了并出现了错误。因此,我不得不使用“delete * from table;”语句进行重置。我确实删除了所有记录,但当我再次插入记录时(这次使用insert into语句),它从我之前插入的年份后一年开始递增ID(即“它没有刷新”)。
注意:我正在使用MySQL 5.5和InnoDB引擎。
我的努力:
- I tried
ALTER TABLE table1 AUTO_INCREMENT=0;
(Reference Second Answer) ---> IT DID NOT HELP. I tried ALTER TABLE table1 DROP column; (Reference- answer 1) --->
Error on rename of table1
Deleted the table again and tried to do:
DBCC CHECKIDENT('table1', RESEED, 0);
(Reference) --->
Syntax error at "DDBC"
-Unexpected INDENT_QUOTED
(This statement is right after the delete table statement, if that matters)In this article, under the section named "Auto Increment Columns for INNODB Tables" and the heading "Update 17 Feb 2009:", it says that in InnoDB truncate does reset the AUTO_INCREMENT index in versions higher than MySQL 4.1... So I want some way to truncate my table, or do something else to reset the AUTO_INCREMENT index.
问题:
当我删除表中的数据时,有没有一种方法可以重置auto_increment? 我需要一种解决DDBC CHECKINDENT错误的方法,或者以某种方式截断被另一个表外键约束引用的表。
(dates)
替换为(id, dates)
对。这样,你就可以手动分配ID值了。 - Micha Wiedenmanntruncate
吗?(然后当然在之后重新启用它们) - user330315auto_increment
只是方便之举。想象一下带有default
选项的列。您可以省略此列的值,而默认值将被使用。auto_increment
列类似地起作用,只是使用递增值。(auto_increment
不是“智能”的,因为它不会搜索第一个空闲值,而是使用 1 + $theLastValueUsedByAutoIncrement(如果我没有弄错的话))。 - Micha Wiedenmann