Timeline for How should I update ID field values for all records based on previous values?
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 29, 2012 at 0:33 | comment | added | Micah Bolen | Yes, in my case, another table was referencing these values. I had to perform the same update procedure on that table as well. | |
Mar 28, 2012 at 17:53 | comment | added | atxdba | I agree with ypercube's comment. | |
Mar 28, 2012 at 16:13 | comment | added | ypercubeᵀᴹ |
@atxdba: But ths (your comment) way will not take care of any referencing columns in other tables. While your Update will (as long as there is an ON UPDATE CASCADE ).
|
|
Mar 28, 2012 at 2:05 | comment | added | atxdba | If the tables in on the same server you could just run insert into newtable (col2, col3, .. colN) select col2, col3, colN from oldtable; Where you leave out your id field in bot the values list and the select list. This assumes your id column is an auto_increment field. Then you just let mysql assign new ids to the rows in the new table | |
Mar 28, 2012 at 1:39 | comment | added | Micah Bolen | Thanks, the second suggestion worked well for the id field (which is a bigint(20) in my case). I'm glad you pointed out to find the max value first. I needed to update these columns in this way because I will be importing them into another duplicate table (duplicate structure; not duplicate records) and did not want the import to fail because of duplicate records. | |
Mar 28, 2012 at 1:31 | vote | accept | Micah Bolen | ||
Mar 28, 2012 at 0:59 | history | answered | atxdba | CC BY-SA 3.0 |