So I recently switched servers, but there is a day inbetween the switch of servers where the data didn't get carried over. I have exported the missing data in a CSV.

I know there is 617 rows to be inserted into the "primary" database, problem is there is entries which have already taken the "primary key" (in this case, it is called "id"). This ID auto increments by 1.

What I would like to do, is the following:

starting at id = 552611 ADD $ID + 618 & repeat till end of table. 

This would allow me to insert the 617 keys starting at:

id = 552611

Ending at:

id = 553228

My SQL-Foo is not that strong! Can anybody point me in the right direction?

  • I'm not sure what you propose to do is actually necessary. Why not just insert the records and give them a new ID?
    – mendosi
    Commented Feb 11, 2017 at 4:02

1 Answer 1


Since you're changing the identity of the row, can we assume that it's not used as a foreign key of another table? If it's only purpose is to uniquely identify the row of the table it's on, then don't bother attempting to assign it a new identity because it's already auto incremented by one, upload your CSV without specifying the id column and it will take care of the id.

You'd have to worry about key collision and identity_insert etc, it's just a mess, but if your heart is set on it, there are ways it could be done.

  • Yea, then the ID to CallDate wouldn't line up, but since our reports only use CallDate to pull from this table, I realized today that seems logical and that I may be A) Overthining and B) Putting more work in than needed Commented Feb 11, 2017 at 16:10
  • @FreeSoftwareServers - ORDER BY CallDate, id resolves that problem.x
    – Rick James
    Commented Feb 11, 2017 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.