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) mysql免安装版打包问题 使用myisamchk *.MYI检查表时,提示“.MYI”文件不存在 innodb plugin后的问题 apache 链接MySQL出现如下错误?? 求一sql语句 MYSQL一台机器上起多个服务,这多个服务可以同时访问同一数据区吗? 关于中文字符的问题 如何以UTF8的形式插入一条记录到MySQL数据库 Mysql是否不支持sub select,我用的是4.0 version 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)