dsxpt62448 2011-09-08 20:31
浏览 282
已采纳

PHPMyAdmin / MySql - 添加ID字段和自动填充ID号

I have an extremely large database table - nearly 20 million records.

The records do not have a unique ID number. So, I've inserted the new field.

Now, I would like to populate it with ID numbers, increasing by 1, starting with the first ID number being 10,000,001.

FYI - I am using WAMP on a local machine and I've dialed all my max times upto 5000 seconds and dialed up several other variables in php.ini and mysql.ini in order to do the upload in the first place (which took more than 10 hours!!).

In the past, or with other DB's, I might have exported the data into excel and then whipped up some text to paste back into phpmyadmin to UPDATE the records. This is fine when working with 5K records, or even 100K records, but this seems unmanagable with 20 million records.

Thanks in advance!!

  • 写回答

3条回答 默认 最新

  • douzhu5900 2011-09-08 20:44
    关注

    Just run these two queries one after the other in the SQL tab:

    ALTER TABLE mytable AUTO_INCREMENT=10000001;
    
    ALTER TABLE mytable ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
    

    MySQL will then create the id field and fill it in sequentially starting at 10000001.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料