版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、COMP231 RevisionPrepared by Raymond WongCOMP2311Revision1. ER DiagramPhase 1 and Phase 3ER-diagram, Relation and proof of the 3rd normal formE.g. Student takes a courseStudentStudent ID UniqueStudent NameCourseCourse ID UniqueCourse NameStudentStudent IDStudent NameCourseCourse IDCourse NameCOMP2312
2、Revision1. ER DiagramE.g. Student takes a courseStudentStudent IDStudent NameCourseCourse IDCourse NameTakeAssumption:Each student takes at least one courseEach course is taken by at least one studentSchemaStudentCourseTake(Student ID, Student Name)(Course ID, Course Name)(Student ID, Course ID)Phas
3、e 1 and Phase 3ER-diagram, Relation and proof of the 3rd normal formCOMP2313Revision1. ER DiagramE.g. Student takes a courseAssumption:Student ID is unique Student ID can uniquely identify a studentCourse ID is unique Course ID can uniquely identify a courseSchemaStudentCourseTake(Student ID, Studen
4、t Name)(Course ID, Course Name)(Student ID, Course ID)Non-trivial Functional DependencyStudent ID Student NameCourse ID Course NameCOMP2314Revision1. ER DiagramSchemaStudentCourseTake(Student ID, Student Name)(Course ID, Course Name)(Student ID, Course ID)Non-trivial Functional DependencyStudent ID
5、Student NameCourse ID Course NameProof of 3NFR is in 3NF if for any A in F A is trivial (A ), or contains a key for R, orA is part of some key(s) for RSchema Student is in 3NFBecausefor Student ID Student Name,Student ID is a key of StudentSchema Course is in 3NFBecausefor Course ID Course Name,Cour
6、se ID is a key of CourseSchema Take is in 3NFBecauseany functional dependencies for Relation Take are trivial.COMP2315Revision2. Relational Algebra/SQLQuery 1: Find the name of all students who take the course taught by “Prof. Wong” studentcoursetakesidsnamecidnamecnameteacherstudent (sid, sname)cou
7、rse (cid, cname, teacher)take (sid, cid)Query 2: Find the name of all students who take ALL courses taught by “Prof. Wong” COMP2316Revision2. Relational Algebra/SQLQuery 1: Find the name of all students who take the course taught by “Prof. Wong” studentcoursetakesidsnamecidnamecnameteacherstudent (s
8、id, sname)course (cid, cname, teacher)take (sid, cid)select S.snamefrom student S, take T, course Cwhere S.sid = T.sid and T.cid = C.cid and C.teacher = Prof. Wongsname ( )teacher=Prof. Wong(course)student takeCourses taught by Prof. WongStudents who take courses taught by Prof. WongRelationalAlgebr
9、aSQLCOMP2317Revision2. Relational Algebra/SQLQuery 2: Find the name of all students who take ALL courses taught by “Prof. Wong” studentcoursetakesidsnamecidnamecnameteacherstudent (sid, sname)course (cid, cname, teacher)take (sid, cid)snameteacher=Prof. Wong(course)(student )Courses taught by Prof.
10、WongA set of cid of courses taught by Prof. WongRelationalAlgebracid ( )set_of_cid A set of sid (of students) who take all courses taught by Prof. Wong(take / set_of cid)Get back snameresult COMP2318Revision2. Relational Algebra/SQLstudentcoursetakesidsnamecidnamecnameteachere.g.1 231537Prof. Wong t
11、eaches 231251252271Peter takesPeter takes only ONE course taught by Prof. Wong Peter DOES NOT take ALL courses taught by Prof. Wong 231537Prof. Wong teaches 231251252271Raymond takes537Raymond takes TWO courses taught by Prof. Wong Raymond TAKES ALL courses taught by Prof. Wong e.g.2COMP2319Revision
12、2. Relational Algebra/SQLe.g.1 231537Prof. Wong teaches 231251252271Peter takesPeter DOES NOT take ALL courses taught by Prof. Wong 231537Prof. Wong teaches 231251252271Raymond takes537Raymond TAKES ALL courses taught by Prof. Wong e.g.2=537Exist?Yes=Exist?NoConclusionA set of courses taught by Prof
13、. WongA set of courses taken by RaymondCourses taughtby Prof. WongCourses takenby a student=Resultif exist = yes, the student DOES NOT take ALL courses taught by Prof. WongIf exist = no, the student takes ALL courses taught by Prof. Wong COMP23110Revision2. Relational Algebra/SQLConclusionCourses ta
14、ughtby Prof. WongCourses takenby a student=ResultQuery 2: Find the name of all students who take ALL courses taught by “Prof. Wong” if exist = yes, the student DOES NOT take ALL courses taught by Prof. WongIf exist = no, the student takes ALL courses taught by Prof. Wong calculateCourses taughtby Pr
15、of. WongCourses takenby student S=ResultFor each student S,If exist = no, the student takes ALL courses taught by Prof. Wong (i.e “not exists” in SQL)COMP23111Revision Query 2: Find the name of all students who take ALL courses taught by “Prof. Wong” calculateCourses taughtby Prof. WongCourses taken
16、by student S=ResultFor each student S,If exist = no, the student takes ALL courses taught by Prof. Wong (i.e “not exists” in SQL)select S.snamefrom student Swhere not existsstudent (sid, sname)course (cid, cname, teacher)take (sid, cid)( select C.cid from course C where teacher = Prof. Wong) ( selec
17、t T.cid from take T where T.sid = S.sid)Courses taught by Prof. Wong Courses taken by student S ( except )SQLCOMP23112RevisionQuery 1: Find the name of all students who take the course taught by “Prof. Wong” select S.snamefrom student S, take T, course Cwhere S.sid = T.sid and T.cid = C.cid and C.te
18、acher = Prof. Wongsname ( )teacher=Prof. Wong(course)student takeRelationalAlgebraSQLQuery 2: Find the name of all students who take ALL courses taught by “Prof. Wong” snameteacher=Prof. Wong(course)(student )cid ( )set_of_cid (take / set_of cid)result RelationalAlgebraSQLselect S.snamefrom student
19、Swhere not exists( select C.cid from course C where teacher = Prof. Wong) ( select T.cid from take T where T.sid = S.sid) ( except )One of the courses taught by Prof. WongAll courses taught by Prof. WongNatural JoinNatural JoinDivisionNot exists(Except)COMP23113Revision2. Relational Algebra/SQLQuery
20、 3: Find the cid of all courses of class size 10studentcoursetakesidsnamecidnamecnameteacherstudent (sid, sname)course (cid, cname, teacher)take (sid, cid)Query 4: Find the cid and cname of all courses of class size 10COMP23114Revision2. Relational Algebra/SQLQuery 3: Find the cid of all courses of class size 10studentcoursetakesidsnamecidnamecnameteacherstudent (sid, sname)course (cid, cname, teacher)take (sid, cid)select T.cidfrom take Tgroup by T.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 莫兰迪年终总结模板
- 2026三个面试题目及答案
- 2026商学院讲师面试题及答案
- 2026声乐课的面试题目及答案
- 合作股份退出协议书
- 结婚证分居协议书
- 餐饮合作退出协议书
- 收养抚育协议书
- 怀孕安全协议书
- 银行个人借款合同范本
- 2026年高一历史学业水平考试知识点归纳总结(复习必背)
- (新版)ISO37301-2021合规管理体系全套管理手册及程序文件(可编辑!)
- 2024-2025学年广东省深圳市福田区七年级(下)期末语文试卷
- 特殊岗位护理人员准入申请表
- “教学做合一”-构建初中“三有”高效化学课堂策略研究 论文
- GB/T 2421-1999电工电子产品环境试验第1部分:总则
- 变电站无功补偿装置课件
- 医院消毒供应中心管理规范清洗消毒及灭菌效果监测标准课件
- 加工中心点检表
- 高等数学上册ppt课件完整版
- GB∕T 29017-2012 连续式喷码机
评论
0/150
提交评论