How to re-assign AUTO_INCREMENT column for every row in a MySQL table using PHP

后端 未结 4 1892
傲寒
傲寒 2020-12-31 09:55

I have an image gallery which website members can upload images to. When an image is uploaded, a MySQL row is written, containing various pieces of information about the ima

4条回答
  •  天命终不由人
    2020-12-31 10:24

    I found this to work perfectly and quite quickly so here it is:

    ALTER TABLE tablename DROP id
    
    ALTER TABLE tablename ADD id INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (id), AUTO_INCREMENT=1
    

    I know this isn't the proper approach however for my specific situation this is exactly what was needed. There is nothing within the table I was using that is referred to either from or to another table.

提交回复
热议问题