ALTER TABLE tablename AUTO_INCREMENT = 10000000
This query is taking long time to update. Why? I need to optimize this query.
Reset the auto increment fieldALTER TABLE `table` AUTO_INCREMENT = number; Replacing 'number' with the result of the previous command plus one and replacing table with the table name. If you deleted all the rows in the table, then you could run the alter table command and reset it to 0.
The TRUNCATE TABLE statement in MySQL completely deletes the table's data without removing a table's structure and always resets the auto-increment column value to zero.
MySQL AUTO INCREMENT Field Auto-increment allows a unique number to be generated automatically when a new record is inserted into a table. Often this is the primary key field that we would like to be created automatically every time a new record is inserted.
To disable or remove the auto increment from a column in MySQL Table, you can simply Modify the column with same data type but without auto_increment clause.
ALTER TABLE causes a rebuild of the entire table - if your table contains many rows,this can take ages.
If you just need to bump up the value of the auto_increment value, the quickest way is to insert a dummy row (and then delete that roow if need be). This will only take a fraction of a second, whereas ALTER TABLE can take days for a large table.
For example, suppose I have a table with an auto_increment ID column and other columns col1, col2...:
insert into autoinc_table set ID = 10000000;
delete from autoinc_table where ID = 10000000;
user and admin data must be distinguished not by id, but by another field. If you would treat an id as an abstract identifier with no other meanings it will save you a lot of time and resources, trust me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With