1、数据库原理实验报告二LIAOCHENG UNIVERSITY计算机学院实验报告【 2015 2016 学年第 2 学期】【一、基本信息】【实验课程】数据库原理与应用【设课形式】独立 非独立 【课程学分】0.5【实验项目】实验二、SQL数据操作及查询【项目类型】基础 综合 设计 研究创新 其它 【项目学时】4【学生姓名】傅雪晨【学 号】2014204359【系别专业】电子商务【实验班组】 2014.06【同组学生】 【实验室名】综合实验楼 【实验日期】【报告日期】【二、实验教师对报告的最终评价及处理意见】实验成绩: (涂改无效) 指导教师签名: 年 月 日注:要将实验项目、实验课程的成绩评定及课
2、程考核办法明确告知学生,并报实验管理中心备案【三、实验预习】实验条件(实验设备、软件、材料等): 实验2 SQL数据操作及查询实验目的:1. 向实验1建立的表中添加数据(元组), 掌握INSERT语句的用法;2. 修改基本表中的数据, 掌握UPDATE语句的用法;3. 删除基本表中的数据,掌握DELETE语句的用法;4. 体会数据完整性约束的作用, 加深对数据完整性及其约束的理解。5. 熟练掌握SELECT语句,能够运用该语句完成各种查询。实验内容:1. 使用INSERT语句将教材P82表中的数据添加到数据库STUDENTDB中.2. Insert into student59select 2
3、01215121,李勇,男,20,CS,unionselect 201215122,刘晨,女,19,CS,unionselect 201215123,王敏,女,18,MA,unionselect 201215125,张立,男,19,IS,select * from student59select * from course59select * from sc59alter table course59 NOCHECK Constraint fk_cpnoInsert into course59select 1,数据库,5,4union select 2,数学,2unionselect 3,信息
4、系统,1,4union select 4,操作系统,6,3union select 5,数据结构,7,4union select 6,数据处理,2union select 7,PASCAL语言,6,4 alter table course59 CHECK Constraint FK_course59_course59Insert into sc59select 201215121,1,92 unionselect 201215121,2,85 unionselect 201215121,3,88 unionselect 201215122,2,90 unionselect 201215122,
5、3,80 alter table sc59 CHECK Constraint fk_S_calter table sc59 NOCHECK Constraint fk_S_c3. 将教材P70表中的数据添加到数据库SPJDB中. 体会执行插入操作时检查实体完整性规则、参照完整性规则和用户定义完整性规则的效果.Insert into S59select s1,精益,20,天津unionselect s2,盛锡,10,北京unionselect s3,东方红,30,北京unionselect s4,丰泰盛,20,天津unionselect s5,为民,30,上海Insert into P59sel
6、ect p1,螺母,红,12 unionselect p2,螺栓,绿,17 unionselect p3,螺丝刀,蓝,14 unionselect p4,螺丝刀,红,14 unionselect p5,凸轮,蓝,40 unionselect p6,齿轮,红,30Insert into J59select J1,三建,北京unionselect J2,一汽,长春unionselect J3,弹簧厂,天津unionselect J4,造船厂,天津unionselect J5,机车厂,唐山unionselect J6,无线电厂,常州unionselect J7,半导体厂,南京Insert into
7、SPJ59select S1,P1,J1,200unionselect S1,P1,J3,100unionselect S1,P1,J4,700unionselect S1,P2,J2,100unionselect S2,P3,J1,400unionselect S2,P3,J2,200unionselect S2,P3,J4,500unionselect S2,P3,J5,400unionselect S2,P5,J1,400unionselect S2,P5,J2,100unionselect S3,P1,J1,200unionselect S3,P3,J1,200unionselect
8、S4,P5,J1,100unionselect S4,P6,J3,300unionselect S4,P6,J4,200unionselect S5,P2,J4,100unionselect S5,P3,J1,200unionselect S5,P6,J2,200unionselect S5,P6,J4,500select * from S59select * from P59select * from J59select * fromSPJ594. 删除student表中学号为201215121的学生,体会执行删除操作时检查参照完整性规则的效果.将参照完整性中的删除规则改为“级联(层叠)”(
9、CASCADE),重新删除该学生信息。delete from student59 where sno=201215121alter table sc59 drop Constraint fk_S_calter table sc59 add Constraint FK_SC_sno_cascadeforeign key (sno) references student59(sno)on delete cascade on update cascade5. 更新student表中201215122学生的新学号为201215128,体会执行更新操作时检查参照完整性规则的效果.将参照完整性中的更新规则
10、改为“级联”,重新更新该学生信息。update student59set sno=201215128where sname=刘晨select * from student596. 设计一组更新操作, 它需要另外一个表中的数据作为更新条件(如将选修了“信息系统”课程的成绩均提高15% )。update sc59set grade=grade*1.15from course59 where o=o and cname=信息系统select * from sc597. 设计一个删除操作,它需要另外一个表中的数据作为删除条件(如将“刘晨”的选课记录删除 )。select * from sc59sele
11、ct * from student59delete from sc59from student59 where sc59.sno=student59.sno and sname=刘晨7. 完成P128习题4和习题5中(1)(7)的查询。(1)找出所有供应商的姓名和所在城市select sname,city from S59(2)找出所有零件的名称、颜色、和重量select pname,color,weight from P59(3)找出使用供应商S1所供应零件的工程号码select jno from SPJ_392 where sno=S1(4)找出工程项目J2使用的各种零件的名称及其数量se
12、lect pnam,weight from P59,SPJ59 where P59.pno=SPJ59.pno and jno=J(5)找出上海厂商供应的所有零件号码select distinct pno from SPJ59,S59 where S59.sno=SPJ59.sno and city=上海(6)找出使用上海产的零件的工程名称select distinct JName from SPJ59,S59,J59 where S59.sno=SPJ59.sno and J59.jno=SPJ59.jno(7)找出没有使用天津产的零件的工程号码select jno from J59 whe
13、re jno not in (select jno from SPJ59,S59 where SPJ59.sno=S59.sno and city=天津)8. 完成以下查询:(1)查询所有课程都及格的学生信息。select * from student59 where sno not in(select sno from sc59 where grade(select avg(grade) from sc59)(7)查询只选修了2号课程的学生的信息,可以使用集合查询。SELECT SnoFROM sc59WHERE Cno=2(8)查询所有计算机系学生的学号、选修课程号以及分数。(使用IN谓词
14、)。select sno,cno,gradefrom sc59where sno in (select snofrom student59where sdept=cs)(9)查询选修了课程名为“操作系统”的学生学号和姓名。select student59.sno ,snamefrom student59where sno in(select sno from sc59 where cno in (select cno from course59 where cname=信息系统) (10)查询所有计算机系学生的学号、选修课程号以及分数(使用EXISTS谓词)。select sno,cno,gradefrom sc59where exists ( select snofrom student59where sdept=cs )实验设计方案(实验方法、步骤、操作过程、设计型实验、实验数据记录表格):实验预习成绩(涂改无效)合格不合格【四、实验过程、数据和实验结果记录】实验方法、步骤、操作过程的记录描述或程序代码。实验过程中输入/输出数据、程序运行结果的记录。(可加附页)记录成绩(涂改无效)合格不合格【五、实验结果分析】
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2