日期:2014-05-16  浏览次数:20704 次

MYSQL语法问题,求解
简单描述:

现有一个网站,庞大的数据量。因为一些文章的删除,所以主键ID已经不连续了。

有一些文章。想把他插入到现有的数据库里,一条条的修改现有数据库。 注意是修改,而不是增加。

忽略文章分割等等问题。

比如说

update 表名 set 字段='文章1' where id=1
update 表名 set 字段='文章2' where id=3
update 表名 set 字段='文章3' where id=4
update 表名 set 字段='文章4' where id=8
......


ID在递增,但是不规律

------解决方案--------------------
加一个临时字段,如 ss int(1).
然后:

for($i=0;$i<10000;$i++){

mysql_query("update 表名 set 字段='文章 $i',ss=1 where ss=0 order by id asc limit 1");

}

最后删除 ss 字段.