资源预览内容
第1页 / 共21页
第2页 / 共21页
第3页 / 共21页
第4页 / 共21页
第5页 / 共21页
第6页 / 共21页
第7页 / 共21页
第8页 / 共21页
第9页 / 共21页
第10页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
LIAOCHENGLIAOCHENG UNIVERSITYUNIVERSITY计算机学院实验报告计算机学院实验报告【 20152015 20162016 学年第学年第 2 2 学期学期】【 【一、基本信息一、基本信息】 】【 【实验课实验课程程】 】数据数据库库原理与原理与应应用用【 【设课设课形式形式】 】独立 非独立 【 【课课程学分程学分】 】0.5【 【实验项实验项目目】 】实验实验二、二、SQL 数据操作及数据操作及查询查询【 【项项目目类类型型】 】基础 综合 设计 研究创新 其它 【 【项项目学目学时时】 】4【 【学生姓名学生姓名】 】傅雪晨傅雪晨【 【学学 号号】 】2014204359【 【系系别专业别专业】 】电电子商子商务务【 【实验实验班班组组】 】 2014.062014.06【 【同同组组学生学生】 】 【 【实验实验室名室名】 】综综合合实验实验楼楼 【 【实验实验日期日期】 】【 【报报告日期告日期】 】【 【二、二、实验实验教教师对报师对报告的最告的最终评终评价及价及处处理意理意见见】 】实验成绩: (涂改无效)指导教师签名: 年 月 日注:要将实验项目、实验课程的成绩评定及课程考核办法明确告知学生,并报实验管理中心备案【 【三、三、实验预习实验预习】 】实验条件(实验设备、软件、材料等): 实验实验 2 SQL 数据操作及查询数据操作及查询实验目的:实验目的:1. 向实验 1 建立的表中添加数据(元组), 掌握 INSERT 语句的用法; 2. 修改基本表中的数据, 掌握 UPDATE 语句的用法; 3. 删除基本表中的数据,掌握 DELETE 语句的用法; 4. 体会数据完整性约束的作用, 加深对数据完整性及其约束的理解。 5. 熟练掌握 SELECT 语句,能够运用该语句完成各种查询。实验内容:实验内容:1. 使用 INSERT 语句将教材 P82表中的数据添加到数据库 STUDENTDB 中. 2. Insert into student59select 201215121,李勇,男,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,信息系统,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,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 P59select p1,螺母,红,12 unionselect p2,螺栓,绿,17 unionselect p3,螺丝刀,蓝,14 unionselect p4,螺丝刀,红,14 unionselect p5,凸轮,蓝,40 unionselect p6,齿轮,红,30 Insert into J59select J1,三建,北京unionselect J2,一汽,长春unionselect J3,弹簧厂,天津unionselect J4,造船厂,天津unionselect J5,机车厂,唐山unionselect J6,无线电厂,常州unionselect J7,半导体厂,南京 Insert into 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 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 的学生,体会执行删除操作时检查参照完整性规则的效果.将 参照完整性中的删除规则改为“级联(层叠)”(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,体会执行更新操作时检查参照完整性 规则的效果.将参照完整性中的更新规则改为“级联” ,重新更新该学生信息。update student59set sno=201215128where sname=刘晨 select * from student596. 设计一组更新操作, 它需要另外一个表中的数据作为更新条件(如将选修了“信息系统”课程的 成绩均提高 15% )。update sc59set grade=grade*1.15from course59 where sc59.cno=course59.cno and cname=信息系统 select * from sc597. 设计一个删除操作,它需要另外一个表中的数据作为删除条件(如将“刘晨”的选课记录删除 )。select * from sc59select * 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 使用的各种零件的名称及其数量 select 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 where 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 谓词)。 select sno,cno,gradefrom sc59where sno in (select snofrom student59where sdept=cs)(9)查询选修了课程名为“操作系统”的学生学号和姓名。 select student59.sno ,snamefrom student59whe
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号