mysql replace into或update 能否更新主键? 我想把主键的值给替换掉 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 replace into 是不行的,它本身就是按主键来查找,否则就insert 了mysql> create table tx (id int primary key,f1 int);Query OK, 0 rows affected (0.06 sec)mysql> select * from tx;+----+------+| id | f1 |+----+------+| 1 | 10 || 2 | 20 |+----+------+2 rows in set (0.00 sec)mysql> REPLACE tx VALUES (1,30);Query OK, 2 rows affected (0.05 sec)mysql> select * from tx;+----+------+| id | f1 |+----+------+| 1 | 30 || 2 | 20 |+----+------+2 rows in set (0.00 sec)mysql> REPLACE tx VALUES (3,30);Query OK, 1 row affected (0.06 sec)mysql> select * from tx;+----+------+| id | f1 |+----+------+| 1 | 30 || 2 | 20 || 3 | 30 |+----+------+3 rows in set (0.00 sec)mysql> update tx set id=9 where id=1;Query OK, 1 row affected (0.08 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from tx;+----+------+| id | f1 |+----+------+| 2 | 20 || 3 | 30 || 9 | 30 | // PK id was updated.+----+------+3 rows in set (0.00 sec)mysql> 用PQexec阻塞,急急急!! mysql工具使用(mysqlbinlog等) Mysql 执行时间 安装发现失败 mysql与c++的一些问题请教 谁介绍一本Mysql或oracle入门的书吧 PostgreSQL 分组查询问题 请问在asp中连接my sql的语句怎么写?使用什么办法? porsql? MYSQL double float demical 的区别 interactive_timeout和wait_timeout的区别 请各位大虾帮忙啊,3表联查问题
Query OK, 0 rows affected (0.06 sec)mysql> select * from tx;
+----+------+
| id | f1 |
+----+------+
| 1 | 10 |
| 2 | 20 |
+----+------+
2 rows in set (0.00 sec)mysql> REPLACE tx VALUES (1,30);
Query OK, 2 rows affected (0.05 sec)mysql> select * from tx;
+----+------+
| id | f1 |
+----+------+
| 1 | 30 |
| 2 | 20 |
+----+------+
2 rows in set (0.00 sec)mysql> REPLACE tx VALUES (3,30);
Query OK, 1 row affected (0.06 sec)mysql> select * from tx;
+----+------+
| id | f1 |
+----+------+
| 1 | 30 |
| 2 | 20 |
| 3 | 30 |
+----+------+
3 rows in set (0.00 sec)mysql> update tx set id=9 where id=1;
Query OK, 1 row affected (0.08 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from tx;
+----+------+
| id | f1 |
+----+------+
| 2 | 20 |
| 3 | 30 |
| 9 | 30 | // PK id was updated.
+----+------+
3 rows in set (0.00 sec)mysql>