Insert sequential number in MySQL

前端 未结 3 2031
無奈伤痛
無奈伤痛 2020-12-05 13:57

I added an empty column to a table and now I want to insert sequential numbers to its rows. Is it possible to do it using SQL?

3条回答
  •  温柔的废话
    2020-12-05 14:33

    Run the following queries to have incremented value in yourField column:

    SELECT @i:=0;
    UPDATE yourTable SET yourField = @i:=@i+1;
    

提交回复
热议问题