mysql set 子表,mysql update set 更新表数据

1、update ...set...where...

题目:修改students id=2的name为“yanxia”

mysql>update  students  set  name ="yanxia" where id=2;

Query OK, 1 row affected (0.04 sec)

Rows matched: 1  Changed: 1  Warnings: 0

2、更新(修改)多个字段

mysql> select*from students;

+----+---------+-----+-----+-------------+

| id | name    | sex | age | tel        |

+----+---------+-----+-----+-------------+

|  1 | lili    | f  |  12 | 13501665963 |

|  2 | yanxia  | m  |  25 | 15101122005 |

|  3 | jujo    | m  |  21 | 15610055009 |

|  4 | jojo    | f  |  24 | 18701559960 |

|  5 | kaite  | f  |  20 | -          |

|  6 | hathway | m  |  21 | -          |

|  7 | lili    | f  |  11 | 15110021003 |

|  8 | LiLi    | f  |  10 | 18710051006 |

+----+---------+-----+-----+-------------+

8 rows in set (0.00 sec)

mysql>update  students  set  name="lili",name="jojo"  where  age<20;

Query OK, 3 rows affected (0.04 sec)

Rows matched: 3  Changed: 3  Warnings: 0

mysql>select*from students;

+----+---------+-----+-----+-------------+

| id | name    | sex | age | tel        |

+----+---------+-----+-----+-------------+

|  1 | jojo    | f  |  12 | 13501665963 |

|  2 | yanxia  | m  |  25 | 15101122005 |

|  3 | jujo    | m  |  21 | 15610055009 |

|  4 | jojo    | f  |  24 | 18701559960 |

|  5 | kaite  | f  |  20 | -          |

|  6 | hathway | m  |  21 | -          |

|  7 | jojo    | f  |  11 | 15110021003 |

|  8 | jojo    | f  |  10 | 18710051006 |

+----+---------+-----+-----+-------------+

8 rows in set (0.00 sec)

3、设置age字段的值

mysql>select*fromstudents;

+----+---------+-----+------+

| id | name    | sex | age  |

+----+---------+-----+------+

|  1 | kimi    | f  |  12 |

|  2 | hathway | m  | NULL |

|  3 | tony    | f  | NULL |

+----+---------+-----+------+

3 rows in set (0.00 sec)

mysql> update students set age =15 where id >=2;

Query OK, 2 rows affected (0.01 sec)

Rows matched: 2  Changed: 2  Warnings: 0

mysql>select*from students;

+----+---------+-----+------+

| id | name    | sex | age  |

+----+---------+-----+------+

|  1 | kimi    | f  |  12 |

|  2 | hathway | m  |  15 |

|  3 | tony    | f  |  15 |

+----+---------+-----+------+

3 rows in set (0.00 sec)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值