现在有这样的数据
‘no’
1
2
3
4
5'no' 是关键字现在想update table set 'no' = 'no' + 1但是爆关键字重复!求大神help一下!谢谢!

解决方案 »

  1.   

    mysql> create table test2(no int);
    Query OK, 0 rows affected (0.03 sec)mysql> insert into test2 values(1);
    Query OK, 1 row affected (0.01 sec)mysql> update test2 set no=no+1;
    Query OK, 1 row affected (0.01 sec)
    Rows matched: 1  Changed: 1  Warnings: 0mysql> select * from test2;
    +------+
    | no   |
    +------+
    |    2 |
    +------+
    1 row in set (0.00 sec)mysql> 
      

  2.   

    还有你没将这个table设关键字你先插多几条连续的数据,然后在执行update语句吧!就有错了!CREATE TABLE `test2` (
      `no` int(11) NOT NULL DEFAULT '0',
      PRIMARY KEY (`no`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8insert into test2 values(1);
    insert into test2 values(2);
    insert into test2 values(3);
    insert into test2 values(4);
    update test2 set no=no+1;
      

  3.   

    update test2 set no=no+1 order by no desc;
      

  4.   


    good boy其实我都有想过这么干的但以为不行!!差点想用存储过程了!!!高人就是高谢谢了!
      

  5.   

    三楼版大确实好方法。
    也可以这样:
    mysql> create table t(id int primary key);
    Query OK, 0 rows affected (0.05 sec)mysql> insert into t values(1), (2), (3);
    Query OK, 3 rows affected (0.01 sec)
    Records: 3  Duplicates: 0  Warnings: 0mysql> update t set id=id+1;
    ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY'
    mysql> alter table t drop primary key;
    Query OK, 3 rows affected (0.13 sec)
    Records: 3  Duplicates: 0  Warnings: 0mysql> update t set id=id+1;
    Query OK, 3 rows affected (0.03 sec)
    Rows matched: 3  Changed: 3  Warnings: 0mysql> select * from t;
    +----+
    | id |
    +----+
    |  2 |
    |  3 |
    |  4 |
    +----+
    3 rows in set (0.00 sec)mysql> alter table t modify id int primary key;
    Query OK, 3 rows affected (0.14 sec)