I know this is an old question, but I stumbled upon it today looking for an answer myself. Here was my solution, which seems to work better than what was here provided. In my particular case, I want some ID's to be linked to each other. In my table I have a column lkMother which records the chain of events. Basically I want to record the price of a widget on such and such a date. Then I want to record the new price as another entry in the table, but I want to show that one of these items replaces the other. We may add several price changes. Then we get a notice from our supplier that they have come out with widget 2.0 to replace the original widget. Even though they aren't exactly the same thing, I want to record that they are, as far was are concerned a replacement.
So this is what I do.
Original Item receives ID Number
Some time later we receive a replacement. The replacement receives the Original Items ID number. The Original item is assigned the next available ID, but its Original ID is recorded in the lkMother column.
Repeat ad infinitem
So when a customer calls and says they need a replacement for a part they purchased on such and such a date, I look up the part, go to the lkMother column which gives me the current equivalent.
Here is stored procedure that swaps the IDs. Notice, this procedure requires that there be no item in the table with an ID = 1. It could be easily modified to fit another scenario.
'''
CREATE PROCEDURE `noe_pricebookswapids` (intid1 INT, intid2 INT)
BEGIN
SET SQL_SAFE_UPDATES = 0;
UPDATE `Order`.tblPrice
SET ID = 1 WHERE ID = intid1;
UPDATE `Order`.tblPrice
SET ID = intid1 WHERE ID = intid2;
UPDATE `Order`.tblPrice
SET ID = intid2 WHERE ID = 1;
END