版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、COMP231Relational ModelCOMP2311OutlineIntroductionTerminologyER-to-Relational MappingCOMP2312IntroductionThe relational model was first introduced by Ted Codd of IBM Research in 1970and attracted due to its simplicity, elegance and mathematical foundationsThe model uses the concept of a mathematical
2、 relation which looks like a table of valuesCOMP2313OutlineIntroductionTerminologyER-to-Relational MappingCOMP2314TerminologyRelation table; denoted by R(A1, A2, ., An) where R is a relation name and (A1, A2, ., An) is the relation schema of RAttribute (column) denoted by AiTuple (Record) rowAttribu
3、te value value stored in a table cellDomain legal type and range of values of an attributedenoted by dom(Ai)Attribute: AgeDomain: 0-100Attribute: EmpNameDomain: 50 alphabetic charsAttribute: SalaryDomain: non-negative integerCOMP2315TerminologyAttributes/Columns (collectively as a schema)Tuples/Rows
4、Relation Name/Table NameCOMP2316SchemaThe relation schema is (Name, Student-id, Age, CGA)ORThe primary key is underlined in the aboveNameStudent-idAgeCGACOMP2317Foreign KeyA foreign key is a set of attributes in one relation r that is used to refer to a tuple in another relation s. (it must correspo
5、nd to the primary key of the second relation)COMP2318Foreign KeyStudent(Student-id, Student-Name)Take(Student-id, Course-id, semesterNo)Student-id in relation Student is a primary keyStudent-id in relation Take is a foreign key COMP2319Foreign KeyStudent(Student-id, Student-Name)Take(Student-id, Cou
6、rse-id, semesterNo)Course(Course-id, Course-Name)Course-id in relation Course is a primary keyCourse-id in relation Take is a foreign keyCOMP23110OutlineIntroductionTerminologyER-to-Relational MappingCOMP23111ER-to-Relational MappingTypically, database designers begin with the ER model, which is ver
7、y expressive and user-friendly to humanThen, the ER model is mapped to the relational model for DBMS manipulationsDatabase queries and updates will be written according to the relational modelCOMP23112ER-to-Relational MappingTranslating traditional ER diagramsTranslating Class HierarchyCOMP23113Depe
8、ndentDependent_ofDependentnamesexbdaterelationshipControlsProjectpnamepnumberplocationsupervisorsupervisionsuperviseeworks_onDependent_ofhoursDepartmentEmployeesexnameeidbdateaddrsalaryworks_forManagesstart_datenumberdnameCOMP23114ControlsProjectpnamepnumberplocationworks_onhoursDepartmentEmployeese
9、xnameeidbdateaddrsalaryworks_forManagesstart_datenumberdnameCOMP23115StepsStep 1 (Strong Entity Set) Step 2 (Weak Entity Set)Step 3 (1-to-1 Relationship)Step 4 (1-to-many Relationship)Step 5 (Many-to-many Relationship)Step 6 (Non-binary Relationship)COMP23116Step 1 (Strong Entity)For each strong ent
10、ity set E in the ER schema, create a relation schema R that includes all the attributes of E. choose one set of key attributes of E as a primary key for R.COMP23117DependentDependent_ofDependentnamesexbdaterelationshipControlsProjectpnamepnumberplocationsupervisorsupervisionsuperviseeworks_onDepende
11、nt_ofhoursDepartmentEmployeesexnameeidbdateaddrsalaryworks_forManagesstart_datenumberdnameCOMP23118ProjectpnamepnumberplocationDepartmentEmployeesexnameeidbdateaddrsalarynumberdnameCOMP23119Step 1 (Strong Entity)ExampleWe create the relation schemas EMPLOYEE, DEPARTMENT and PROJECT.nameEMPLOYEEDEPAR
12、TMENTPROJECTeidbdateaddrsexsalarydnamednumberpnamepnumberplocationCOMP23120If there is a derived attribute, what should we do?We have two choices.Choice 1: Include this derived attribute Adv: We can directly obtain the value of the derived attribute Disadv: We may encounter some data inconsistencies
13、Choice 2: NOT include this derived attribute Adv: We can avoid data inconsistency Disadv: We need to perform some operations to obtain the value of the derived attributeCOMP23121If there is a composite attribute, what should we do?We have two choices.Choice 1: Include the high-level attribute only (
14、e.g., address)Choice 2: Include all low-level attributes (e.g., street, city, country)EmployeeaddressstreetcitycountryCOMP23122If there is a multi-valued attribute, what should we do?We have two choices.Choice 1: Include one attribute only (e.g., phone)Choice 2: Create another table containing the p
15、rimary key of the entity set and the multi-valued attributee.g., create a schema PhoneTable (eid, phone)EmployeephoneeidCOMP23123Step 2 (Weak Entity)For each weak entity set W in the ER model, create a relation schema R, and include all attributes.In addition, include the primary key(s) of the owner
16、(s). The primary key of R is the combination of the primary key(s) of the owner(s) and the discriminator of the weak entity set W.COMP23124DependentDependent_ofDependentnamesexbdaterelationshipControlsProjectpnamepnumberplocationsupervisorsupervisionsuperviseeworks_onDependent_ofhoursDepartmentEmplo
17、yeesexnameeidbdateaddrsalaryworks_forManagesstart_datenumberdnameCOMP23125DependentDependent_ofDependentnamesexbdaterelationshipDependent_ofEmployeesexnameeidbdateaddrsalaryCOMP23126Dependenteidsexdependent-namebdaterelationshipCOMP23127Step 3 (1-to-1 Relationship)For each binary one-to-one (1:1) re
18、lationship set R T - SChoose one of the 2 relation schemas, say S,get primary key of T, include it as foreign keys in S. Better if S has total participation in RInclude the attributes of the relationship set R as attributes of S.COMP23128DependentDependent_ofDependentnamesexbdaterelationshipControls
19、Projectpnamepnumberplocationsupervisorsupervisionsuperviseeworks_onDependent_ofhoursDepartmentEmployeesexnameeidbdateaddrsalaryworks_forManagesstart_datenumberdnameCOMP23129DepartmentEmployeesexnameeidbdateaddrsalaryManagesstart_datenumberdnameCOMP23130We include the primary key of EMPLOYEE as forei
20、gn key in DEPARTMENT and rename it mgr_id. We include the attribute startdate of MANAGES and rename it mgr_start_date.DEPARTMENTdnamednumbermgr_idmgr_start_dateCOMP23131Compare the following two choicesto include MANAGES:Add information to EMPLOYEEAdd to DEPARTMENTEMPLOYEEMANAGESDEPARTMENTCOMP23132I
21、n the above, the NULL value is a special value meaning that the value is either unknown or not applicable.Notice that an alternative mapping of a one-to-one relationship set is possible by merging the two entity sets and the relationship into a single relation. This is appropriate when both particip
22、ations are total.Step 3:Advantage: The total number of relations remain unchangedDisadvantage: It may store NULL valuesif there is no total participationCOMP23133DepartmentEmployeesexnameeidbdateaddrsalaryManagesstart_datenumberdnameCan we create a new relation Manages (eid, number, start_date) OrMa
23、nages (eid, number, start_date) for this relationship?Yes. It can be used if there are onlya few relationship instancesAdvantage: It can avoid storing NULL valuesif there is no total participationDisadvantage: There is one additionalrelationCOMP23134Step 4 (1-to-many Relationship)For each binary one
24、-to-many relationship set T - SInclude as foreign key in S the primary key that represents the other entity set T participating in R. Include any attributes of the one-to-many relationship set as attributes of S.COMP23135DependentDependent_ofDependentnamesexbdaterelationshipControlsProjectpnamepnumb
25、erplocationsupervisorsupervisionsuperviseeworks_onDependent_ofhoursDepartmentEmployeesexnameeidbdateaddrsalaryworks_forManagesstart_datenumberdnameCOMP23136ControlsProjectpnamepnumberplocationsupervisorsupervisionsuperviseeDepartmentEmployeesexnameeidbdateaddrsalaryworks_fornumberdnameCOMP23137The p
26、rimary key dnumber of the DEPARTMENT relation schema is included as foreign key in the EMPLOYEE relation schema. We rename it as dno. (The renaming is not necessary but makes the name more meaningful.)nameEMPLOYEEeidbdateaddrsexsalarydnoEMPLOYEEWORKS_FORDEPARTMENTCOMP23138Compare the following 2 cho
27、ices:EMPLOYEEDEPARTMENTAdd employees to departmentAdd department to employeeCOMP23139For SUPERVISON, include the primary key of the EMPLOYEE as foreign key in the EMPLOYEE, and call it super_EMPLOYEEeidbdateaddrsexsalarydnosuper_idpnamePROJECTpnumberplocationdnum For CONTROLS relationship, in
28、clude dnum as foreign key in PROJECT, which references the primary key dnumber of DEPARTMENT.COMP23140ControlsProjectpnamepnumberplocationsupervisorsupervisionsuperviseeDepartmentEmployeesexnameeidbdateaddrsalaryworks_fornumberdnameCan we create a new relation works_for (eid, number) for this relati
29、onship?Yes. COMP23141Step 5 (Many-to-many Relationship)For each binary many-to-many relationship set R, create a new relation schema S to represent R.Include as foreign key attributes in S the primary keys of the relation schemas for the participating entity sets in Rtheir combination will form the
30、primary key of S. Also include attributes of the many-to-many relationship set as attributes of S.COMP23142DependentDependent_ofDependentnamesexbdaterelationshipControlsProjectpnamepnumberplocationsupervisorsupervisionsuperviseeworks_onDependent_ofhoursDepartmentEmployeesexnameeidbdateaddrsalarywork
31、s_forManagesstart_datenumberdnameCOMP23143Projectpnamepnumberplocationworks_onhoursEmployeesexnameeidbdateaddrsalaryCOMP23144Map the many-to-many relationship setsWORKS_ON by creating the relation schema WORKS_ON.Include the primary keys of PROJECT and EMPLOYEE as foreign keys.eidWORKS_ONpnumberhour
32、sCOMP23145Compare the following three choices to include works_onpnumberhoursNullNullC7789A0110A01101A0122C7757nameidbdateaddrsexsalarydnoYeung7080370F20K3Chan3031060M30K4Chan3031060M30K4Wong4010280F10K7Cheung8220985M24K1Cheung8220985M24K1Add to EMPLOYEE Add to PROJECTNew relation WORKS_ONEMPLOYEEWO
33、RKS_ONPROJECTCOMP23146Step 6 (Non-binary Relationship)For each non-binary relationship set, create a new relation schema S to represent R. Include as foreign key attributes in S the primary keys of the participating entity sets. Also include any attributes of the non-binary relationship set as attri
34、butes of S.COMP23147For non-binary relationships,The primary key of S is usually a combination of all the foreign keys that reference the relations representing the participating entity sets. However if any entity set has a key constraint on the relationship (e.g., 1-to-many relationship), the prima
35、ry key of the entity set can be used as a key for the relationship.COMP23148DEPARTMENTdnamemgr_iddnumbermgr_start_datenameEMPLOYEEeidbdateaddrsexsalarydnopnamePROJECTpnumberplocationdnumeidWORKS_ONpnumberhoursResulting relation schemas:COMP23149DEPARTMENTdnamemgr_iddnumbermgr_start_datenameEMPLOYEEeidbdateaddrsexsalarydnosuper_idpnamePROJECTpnumberplocationdnumDEPENDENTeidsexdependent-namebdaterelationshipeidWORKS_ONpnumberhoursResult
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年冬季蔬菜储备合同协议
- 2025年工业互联网平台安全防护策略报告
- 家长在高中数字素养评价中参与度与效果关系研究报告教学研究课题报告
- 高中化学教学中实验教学与生活实践结合的研究课题报告教学研究课题报告
- 长江航运总医院2026年合同制护士公开招聘备考题库(含答案详解)
- 2025年智能传感器五年研究:多参数检测与物联网适配行业趋势
- 《小学低年级绘本阅读教学中的多元智能理论应用研究》教学研究课题报告
- 吴家店镇中心卫生院2025年度公开招聘合同制人员备考题库及完整答案详解
- 2026年双流中学九江实验学校(北区)第一批教师招聘备考题库参考答案详解
- 麻章区2025年大学生乡村医生专项计划招聘备考题库完整答案详解
- 高压开关房管理制度
- 【基于PLC的自动卷缆机结构控制的系统设计10000字(论文)】
- 脑器质性精神障碍护理查房
- GB/T 45481-2025硅橡胶混炼胶医疗导管用
- 护理人员精神科进修汇报
- 2023核电厂射线照相底片数字化技术规范
- 泪道冲洗的技巧与规范
- 2025字节跳动智能广告发布服务合同(模板)
- 福建省泉州市2024-2025学年高一上学期期末质量监测生物试题(原卷版+解析版)
- 2025年湖北省技能高考(建筑技术类)《建筑材料与检测》模拟练习试题库(含答案)
- 《健康体检报告解读》课件
评论
0/150
提交评论