![]() is calculated as MAX(auto_increment_column)+1) WHERE prefix=given-prefix." is unclear given that this is the first mention of the word "prefix" in the document. The manual should probably make *better* mention of the fact that the order in which primary keys are specified determines the semantics by which a new value is selected. In order to reset the auto_increment, in a situation where some of the most recently added rows were deleted, use:ĪLTER TABLE theTableInQuestion AUTO_INCREMENT=1234Īnd future insertions will be numbered from 1234 again (unless you still had rows numbered greater than 1234, and then the future insertions will start from the greatest number + 1 ). Also, as with any major structure change, it's a good idea to backup your table BEFORE you make the change.) ![]() (Keep in mind that DROPping that column will remove all existing data, so if you have exterior resources that rely on that data, or the numbers that are already there, you may break the link. You will notice that all existing rows are renumbered and the next auto_increment number will be equal to the row count plus 1. Hit the limit for the field size, INSERTs generateįor those that are looking to "reset" the auto_increment, say on a list that has had a few deletions and you want to renumber everything, you can do the following.ĭROP the field you are auto_incrementing.ĪLTER the table to ADD the field again with the same attributes. User Comments Posted by Jim Martin on Octo7:57amĪUTO_INCREMENT field /DOES NOT WRAP/. Mysql> ALTER TABLE tbl AUTO_INCREMENT = 100 Than 1, you can set that value with CREATE To start with an AUTO_INCREMENT value other Table would contain a single sequence, not a sequence per Index that begins with the AUTO_INCREMENTĬolumn, if there is one. Multiple indexes, MySQL will generate sequence values using the Happens even for MyISAM tables, for which In this case (when the AUTO_INCREMENT column Grp ENUM('fish','mammal','bird') NOT NULL, Is useful when you want to put data into ordered groups. In this case, the generated value for the Multiple-row inserts to be reproduced correctly on otherĪUTO_INCREMENT on a secondary column in a
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |