mysql中如何用一条语句更新主键增加特定的值

mysql> select * from bai_utf8;
+-----+--------+
| id  | myname |
+-----+--------+
|   1 | aa     |
| 100 | ab     |
| 200 | cc     |
| 300 | dd     |
| 400 | ee     |
| 500 | ff     |
+-----+--------+
6 rows in set (0.00 sec)

mysql> show create table bai_utf8;
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                                                                                                                                                                   |
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| bai_utf8 | CREATE TABLE `bai_utf8` (
  `id` int(11) NOT NULL,
  `myname` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `u_name` (`myname`),
  UNIQUE KEY `u_name2` (`myname`(10))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> update bai_utf8 set id=id+100;
ERROR 1062 (23000): Duplicate entry '200' for key 'PRIMARY'
mysql> update bai_utf8 set id=id+100 order by id desc;
Query OK, 6 rows affected (0.02 sec)
Rows matched: 6  Changed: 6  Warnings: 0

你可能感兴趣的:(MYSQL)