Skip to content
Advertisement

increment value in mysql after the table has been created

I would like to change the value in the second column to increment and also change the current NULL values to start using that incrementing system that begins at a value other than 1. I do see I can use

ALTER TABLE t2 AUTO_INCREMENT = value;

to change the table to start incrementing at the number I want it to but the values them selves are still null how do I change my table from this:

| Id | OtherNumber | Name |
| -- |:-----------:| ----:|
| 1  | NULL        | Bob  |
| 2  | NULL        | Susan|
| 3  | NULL        | Bill |

to this

| Id | OtherNumber | Name |
| -- |:-----------:| ----:|
| 1  | 7           | Bob  |
| 2  | 8           | Susan|
| 3  | 9           | Bill |

How would I make the change if the table is in the hundreds of rows? Thanks

Advertisement

Answer

how about if you leave Id as auto-increment, drop the OtherNumber column, and when you do a select, have OtherNumber be a derived column=Id+6

There, maybe some other Answers will come along. Others could be better.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement