MySQL increasing ID manually
Some times it’s necessary to assign a consecutively increasing ID field to a set of rows. Autoincrement is available, but you would need to leverage an INSERT in order to make use of MySQL’s autoincrement feature. Fortunately, it is possible to do this in place by using a separate counter variable in an UPDATE statement.
The solution given below is largely adapted for MySQL from Phil Haack’s SQL Server recipe. If you’re using MySQL Query Browser, you’ll need to make this a script by clicking File > New Script Tab.
SET @counter = your_starting_index; UPDATE your_table_name SET your_id_column_name=(@counter:=@counter+1);
Make sure to change your_starting_index, your_table_name, and your_id_column_name.
To receive updates on new articles, subscribe to CRF Design today!











