数据更新(数据库实验3)_第1页
数据更新(数据库实验3)_第2页
数据更新(数据库实验3)_第3页
数据更新(数据库实验3)_第4页
数据更新(数据库实验3)_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、数据库基础与实践实验报告实验三 数据更新 班级:惠普测试142班 学号: 姓名:闫伟明日期:2016.11.91 实验目的:1) 掌握SQL进行数据添加的方法;2) 掌握SQL进行数据修改的方法;3) 掌握SQL进行数据删除的方法。2 实验平台:操作系统:Windows xp。实验环境:SQL Server 2000以上版本。3 实验内容与步骤利用实验一创建的sch_id数据库完成下列数据更新,并对语句的功能进行测试。1. 向数据库的每张用户表(除SC表)中至少添加3条元组,其中S表中插入2位计算机专业的同学,一位非计算机专业的同学。代码:insert into D values(D4,动漫)

2、insert into D values(D5,体育)insert into D values(D6,金融)insert into T values (T7,张三,男,30,教授,2000,2000,D4)insert into T values (T8,李四,男,35,讲师,1200,1500,D5)insert into T values (T9,王五,女,40,副教授,1400,1500,D6)insert into S values (S9,李华,男,20,D1)insert into S values (S10,张明,男,21,D1)insert into S values (S11

3、,张丽,女,23,D5)insert into S values (S12,王华,女,18,D6)insert into S values (S13,李欣美,女,18,D4)insert into C values (C6,语文,36)insert into C values (C7,线代,40)insert into C values (C8,数据库,36)insert into C values (C9,马克思,36)insert into TC values (T7,C6)insert into TC values (T8,C7)insert into TC values (T8,C8)

4、insert into TC values (T9,C9)运行结果截图:2. 向SC表中插入选课记录,为计算机专业的同学选上全部课程,成绩取值为空值。代码:delete from SC where exists (select 1 from S,D where SC.sno=S.sno and S.dno=D.dno and D.dn=计算机)insert into SC(sno,cno) select sno,cno from S,C,D where S.dno=D.dno and D.dn=计算机运行结果截图:SC表数据更新后的查询结果截图:select * from SC3. 将课时大于

5、等于80学时的课程全部改为72学时。代码:select cno 课程编号,cn 课程名,ct 课时 from C where ct=80update C set ct=72 where ct=80select cno 课程编号,cn 课程名,ct 课时 from C where ct=72测试记录:C表数据更新前的查询结果截图:更新语句运行结果截图:C表数据更新后的查询结果截图:4. 删除成绩为空值的选课记录。代码:select sno 学号,cno 课程编号,score 分数 from SC where score IS NULLdelete from SC where score IS N

6、ULLselect sno 学号,cno 课程编号,score 分数 from SC测试记录:SC表数据更新前的查询结果截图:运行结果截图:SC表数据更新后的查询结果截图:5. 删除姓名为刘伟的老师的授课记录。代码:select tn 教师姓名 ,cn 所授课程 from TC,T,C where TC.tno=T.tno and TC.cno=C.cno and T.tn=刘伟delete from TC where tno=(select tno from T where tn=刘伟)select tn 教师姓名 ,cn 所授课程 from TC,T,C where TC.tno=T.tn

7、o and TC.cno=C.cno and T.tn=刘伟测试记录:T表数据更新前的查询结果截图:运行结果截图:T表数据更新后的查询结果截图:6. 调整岗位津贴,教授岗贴增长10%,副教授岗贴增长20%,讲师岗贴增长30%。代码:select tn 姓名,prof 职称,sal 工资 from T where prof=教授union allselect tn 姓名,prof 职称,sal 工资 from T where prof=副教授union allselect tn 姓名,prof 职称,sal 工资 from T where prof=讲师-update T set sal=sal

8、*1.1 where prof=教授-update T set sal=sal*1.2 where prof=副教授-update T set sal=sal*1.3 where prof=讲师-一条update语句实现update T set sal=sal*case profwhen 教授 then 1.1when 副教授 then 1.2when 讲师 then 1.3endwhere prof in (教授,副教授,讲师)测试记录:T表数据更新前的查询结果截图:运行结果截图:T表数据更新后的查询结果截图:7. 将基本工资低于平均基本工资的教师的工资增长10%。代码:select tn

9、姓名,prof 职称,sal 工资 from T where sal(select avg(sal) from T)update T set sal=sal*1.1 where sal(select avg(sal) from T)select tn 姓名,prof 职称,sal 工资 from T测试记录:T表数据更新前的查询结果截图:运行结果截图:T表数据更新后的查询结果截图:8. 将基本工资低于同职称教师基本工资的教师工资增长10%。代码:select tn 姓名,prof 职称,sal 工资 from T order by prof ,sal descselect tn 姓名,prof 职称,sal 工资 from T t1 where exists(select 1 from T where t1.salsal and prof=f) order by prof,sal descupdate T set sal=sal*1.1 from T t1 where exists (select 1 from T where t1.sal=2500 or m=2500)2) 如果要修改S表中一位已经选过课的学生的学号(例如:学号从改为),请给出具体的数据更新步骤。- 向S和SC表插入新纪录insert into

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论