Incrementing a field in SQL using PHP

前端 未结 1 575
陌清茗
陌清茗 2021-01-26 02:22

I have a table (T1) with some fields F2, F3 (Columns) with already some values in it .... .

I need to add a new field (F1) to the table (T1) and F1 will be the primary k

相关标签:
1条回答
  • 2021-01-26 03:06

    If you are using MySQL:

    ALTER TABLE myTable
    AUTO_INCREMENT = 1677216 ,
    ADD COLUMN F1 INT PRIMARY KEY AUTO_INCREMENT ;
    

    Existing rows will have the F1 field automatically filled with ids, starting from 1677216.


    If you are worried that it is an integer and not a string, pretend it's a string by never using id, only use RIGHT(id,8)

    0 讨论(0)
提交回复
热议问题