8.3.1语法
语法:
update 表名 set 字段1名字 = 字段1的值,字段2名字=字段2的值 ( where 条件 )
8.3.2更新所有数据
(1)将所有人的成绩设为100
update tb_user set score = 100;
8.3.3根据条件更新
(2)将学号时6的学生 成绩设为59
update tb_user set score = 59 where id = 6;
(3)将名字为ww的学生,成绩为60
update tb_user set score = 60 where name='ww';
8.3.4更新多个字段
(4)将学号时5的学生 成绩设为99 名字为;‘xl’;
update tb_userset score =99,name = 'xl' where id = 5;
#(5)将所有人的成绩减去10分
update tb_user set score = score*0.7;
update tb_user set score = score-10;
8.4删除数据
8.4.1语法
(1)语法:
delete from 表名 where 条件
8.4.2删除所有数据
(1)删除所有的数据
delete from tb_user;
8.4.3根据条件删除
(2)删除学号为1的数据
delete from tb_user where id=1;
##(3)删除名字为ww学生的数据
delete from tb_user where name=‘ww’;
8.4.4truncate删除
(4)删除所有数据
truncate table tb_user;
这篇博客主要介绍了MySQL中更新数据的语法和实践,包括无条件更新所有数据、根据条件更新特定记录以及同时更新多个字段。此外,还详细讲解了删除数据的语法,包括删除全部数据、按条件删除特定记录以及使用`TRUNCATE`命令快速清空表内容。
5万+

被折叠的 条评论
为什么被折叠?



