Reputation: 1008
I have table with fields like id,title,no,url.
I want to auto increment id field
the table already has 1000 records in it with already some assigned ids
Now i want to auto increament the records that are newly inserted only .i do not want to auto increment the already present 1000 records .
Is there way i can do this???
Upvotes: 1
Views: 278
Reputation: 409
Check the largest value of the id
SELECT MAX (ID) FROM TABLE
and make the starting index for this table from the next value (+1)
Upvotes: 0
Reputation: 20046
ALTER TABLE tablename MODIFY id integer (11) auto_increment;
Upvotes: 4
Reputation: 4492
yeah, just add auto increment to the field that has the ids already. The ids must be unique. The next auto_increment will be on the highest id present in the table....Try to use phpmyadmin
Upvotes: 0
Reputation: 26739
Just set column to autoincrement. It will increment only new ids, and will set the autoincrement to max(id) + 1. Even when the column is autoincrement, you can set a value, and you'll change the autoincrement counter.
Please note, you have to create index on id, in order to make it an auto-increment field.
Upvotes: 1