int 作关键字,想update +1,应该如何处理 现在有这样的数据‘no’12345'no' 是关键字现在想update table set 'no' = 'no' + 1但是爆关键字重复!求大神help一下!谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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> 还有你没将这个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; update test2 set no=no+1 order by no desc; good boy其实我都有想过这么干的但以为不行!!差点想用存储过程了!!!高人就是高谢谢了! 三楼版大确实好方法。也可以这样: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) c+mysql的应用领域有那些? 模糊查询的效率怎么这么低呢? 在线等啊!MySql安装问题 如何改变表中的文章id随机为自增 mysql存储过程中可以用字符串替换函数REPLACE吗? 谁有mysql-connector-java-5.0.8-bin-g.jar mysql 数据库并发访问量测试 求一sql语句,有点复杂,在线等 Mysql的存储过程在千万数据面前不给力? Error 1045 MySql 希望大家看看这条语句如何优化! mysql导出问题,,求教
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>
`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;
good boy其实我都有想过这么干的但以为不行!!差点想用存储过程了!!!高人就是高谢谢了!
也可以这样:
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)