Omzy Posted March 3, 2010 Share Posted March 3, 2010 I have field ID in my table (not auto-incremented), what I wish to do is set the ID field of the first row to 200, and then add 1 to the ID on every next row. Quote Link to comment https://forums.phpfreaks.com/topic/194036-update-id-field-of-table/ Share on other sites More sharing options...
Dennis1986 Posted March 3, 2010 Share Posted March 3, 2010 Here's how I would do it: - Create a temptable with similar fields - ALTER TABLE [temptable] AUTO_INCREMENT = 200 - INSERT data from original table into temptable - Empty original table - INSERT back from temptable to original table The actual queries you need I'm not going to write right now (I'm sure someone else would want to) as I'm too tired right now. Quote Link to comment https://forums.phpfreaks.com/topic/194036-update-id-field-of-table/#findComment-1021034 Share on other sites More sharing options...
Omzy Posted March 4, 2010 Author Share Posted March 4, 2010 How do I insert data from one table to another? Quote Link to comment https://forums.phpfreaks.com/topic/194036-update-id-field-of-table/#findComment-1021160 Share on other sites More sharing options...
Dennis1986 Posted March 4, 2010 Share Posted March 4, 2010 You could also set a variable that increases by 1 each update. SET @temp = 200; UPDATE table_name SET ID = @temp := ( @temp +1 ) ORDER BY ID ASC; Quote Link to comment https://forums.phpfreaks.com/topic/194036-update-id-field-of-table/#findComment-1021328 Share on other sites More sharing options...
Omzy Posted March 4, 2010 Author Share Posted March 4, 2010 How do I insert data from one table to another? Quote Link to comment https://forums.phpfreaks.com/topic/194036-update-id-field-of-table/#findComment-1021497 Share on other sites More sharing options...
PFMaBiSmAd Posted March 4, 2010 Share Posted March 4, 2010 http://dev.mysql.com/doc/refman/5.0/en/insert-select.html Quote Link to comment https://forums.phpfreaks.com/topic/194036-update-id-field-of-table/#findComment-1021501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.