Insert sequential number in MySQL

前端 未结 3 2033
無奈伤痛
無奈伤痛 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:49

    try this auto increment if you wanted to have incremental number in your table for each insert that you do

    create table WithAutoInc(somID int AUTO_INCREMENT,somName_ char(100) ,primary key(somID ));
    

    now to insert you can do this

     insert into WithAutoInc (somName_) values ('presley');
    

    the result is

    enter image description here

提交回复
热议问题