Tina Malina
Tina Malina

Reputation: 141

Shifting id values of existing rows in mysql

I have a table in a mysql database, in which every row has an id column with auto increment. The id values start at 1, and end at 639.

What I need to do is change the id column of each row, so that the count doesn't begin at 1 but at 1924.

I tried this:

ALTER TABLE tablename AUTO_INCREMENT=1924;

but that doesn't seem to do what I need, it only resets the future count so that any future rows added start counting at 1924.

I need to change the existing ID values of existing rows.

How do I do that?

Upvotes: 2

Views: 2012

Answers (1)

Hanky Panky
Hanky Panky

Reputation: 46900

  UPDATE myTable SET id=id+1923

Simple as that

Upvotes: 6

Related Questions