sql 练习系列:数据的更新操作

还是接着上一篇博文,我们继续。。。

本文主要练习更新操作,在mysql中实现。

内容相对上一篇博文较少,这是那三张表:


修改“计算机学院”的“李勇”同学的名字为“ 李咏

如果仅有一个sno主键那么:

update s set sname='李咏' where sno='20130101' and sdept ='computer';
--必须写成-->
alter table s drop primary key;
alter table s add primary key(sname);
update s set sname='李咏' where sname='李勇' and sdept ='computer';
这样的话,后期诸多的更新操作会很麻烦,所以干脆把所有涉及到更新的字段统统设置成primary key的属性
alter table s drop primary key;
alter table s add primary key(sname,sno,sid,sdept,sage);
将选修了 10001 课程的学生的分数设置为 60
update sc set grade=60 where cno='1001';
将选修了“大学英语”课程的学生的分数增加 5
update sc set grade=grade+5 where sc.cno=(select cno from c where c.cname='大学英语');
将“计算机学院”的学生的“高等数学”课程的成绩设置为 NULL
Update sc set grade=null where cno=(select cno from c where cname='高数') 
and sno in (select sno from s where sdept='computer');
/* cno和sno必有一个是=,不能同时是in */
删除计算机学院年龄大于 25 岁的男生
Delete from s where sdept='computer' and sage>25 and ssex='男';



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值