当前位置: 代码迷 >> 综合 >> mysql更新数据 update
  详细解决方案

mysql更新数据 update

热度:53   发布时间:2024-01-30 05:40:19.0

原来的mytable表如下:

mysql> select * from mytable;
+----+--------+------+--------------+---------+
| id | name   | sex  | info         | address |
+----+--------+------+--------------+---------+
|  1 | 张三   | 男   | NULL         | NULL    |
|  2 | 李四   | 女   | NULL         | NULL    |
|  3 | 赵六   | 男   | 乐于助人     | NULL    |
+----+--------+------+--------------+---------+
3 rows in set (0.00 sec)

现在要把id= 1的address 值改为   学府花园,代码如下:

mysql> update  mytable set address = '丰镇市学府花园' where id =1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0mysql> select * from mytable;
+----+--------+------+--------------+-----------------------+
| id | name   | sex  | info         | address               |
+----+--------+------+--------------+-----------------------+
|  1 | 张三   | 男   | NULL         | 丰镇市学府花园        |
|  2 | 李四   | 女   | NULL         | NULL                  |
|  3 | 赵六   | 男   | 乐于助人     | NULL                  |
+----+--------+------+--------------+-----------------------+
3 rows in set (0.00 sec)

 注意:更新表(update命令)和更改表(alter命令)语法完全不同,

update  表名  ...

alter table 表名      ...

  相关解决方案