Databases Modifying Data with SQL Deleting Data From a Database Removing Specific Rows

Vaidas Staugaitis
Vaidas Staugaitis
1,431 Points

Auto incremented ID after deleting rows


If I let's say delete the rows with ID's 1 to 6, and only have the ones with 7 and up left, is there any way to sort of move all the ID's so it starts at 1 again, rather than 7, without having to manually update every ID in every row?

1 Answer

Steven Parker
Steven Parker
207,992 Points

Why would you want to do that?

Auto-increment ID's serve the purpose of providing unique identifiers for each row, but there's no real advantage to having them be contiguous. In fact, at some later point it may actually be useful to identify that something was removed even if it cannot be completely restored.

If I did have a compelling reason to make ID's contiguous (though I can't think of one offhand), I would probably copy the existing rows into a new autonumbered table.