e-r建模及关系表转换-例题习题--submitted讲课稿
- 格式:doc
- 大小:217.00 KB
- 文档页数:12
【例5】今有一个医院住院部,设有多个科,每个科有若干医生和病房,病人住在病房中由某个医生负责治疗。
医生总是属于某个科的,但不能跨科;病房也是属于某个科的,不混合使用;病人住在某一科的病房中,一个病房可住多个病人,一个病人由固定医生负责治疗,一个医生可以负责多个病人。
根据上述语义,画出E-R模型。
答案:【例6】学校有若干系,每个系有若干班级和教研室,每个教研室有若干教员,其中有的教授和副教授可以带若干研究生,每个班有多名学生,每个学生选修多门课程,每门课程由若干学生选修。
画出学校的E-R图。
【例7】某商业数据管理系统,业务规定如下:⑴顾客有姓名、单位、电话号码⑵商品有商品编码、商品名称、单价这些实体之间的联系:⑴每一名顾客可能买多种商品,且每一种商品又可能有多名顾客购买⑵顾客每一次购买商品还涉及日期、数量、金额根据上述描述,解答下列各题:①试画出E-R图;②要求在E-R图中标注联系的类型;③指出每一个实体的主码(主关键字);④将E-R图转换成关系模型。
答案:转化的关系模型为:顾客(姓名,单位,电话号码),主键为姓名;商品(商品编码,商品名称,单价),主键为商品编码;购买(姓名,商品编码,日期,数量,金额),主键为(姓名,商品编码,日期),外键:姓名,参照顾客;外键:商品编码,参照商品。
【例7】设某工厂的物资管理系统包含如下的实体:➢仓库:仓库号、仓库面积、电话号码➢零件:零件号、名称、规格、单价、描述➢供应商:供应商号、名称、地址、电话号码、帐号➢职工:职工号、姓名、年龄、职称实体之间的联系如下:➢一个仓库可以存放多种零件,一个零件可以存放多个仓库中。
用库存量来描述某种零件在某个仓库中的数量。
➢一个仓库有多个职工当仓库保管员,一个职工只能在一个仓库中工作。
➢职工之间具有领导和被领导的关系,即仓库主任领导若干保管员。
➢一个供应商可以供应多种零件,反之,一种零件也可以由不同的供应商供应。
(1)根据以上描述,构造E-R模型。
20数据库的物理设计通常分为两步。
①确定数据库的物理结构,在关系数据库中主要指存储结构和存取方法。
②对物理结构进行评价,评价的重点是时间和空间效率。
如果评价结果满足原设计要求,则可进入到数据库实施阶段,否则,就需要重新设计或修改物理结构,有时甚至要返回逻辑设计阶段修改逻辑模型。
5.数据库实施阶段完成数据库的物理设计之后,就要用数据库管理系统提供的数据定义语言和其他实用程序将数据库逻辑设计和物理设计结果严格地描述出来,成为数据库管理系统可以接收的源代码,再经过调试产生目标代码,然后就可以组织数据入库了,这就是数据库实施阶段。
数据库实施阶段包括两项重要的工作,一是数据的载入,二是应用程序的编码和调试。
一般数据库系统中,数据量都很大,而且数据来源于各个不同的部门,数据的组织方式、结构和格式都与新设计的数据库系统有相当的差距,组织数据录入就要将各类源数据从各个局部应用中抽取出来,输入计算机,再分类转换,最后综合成符合新设计的数据库结构的形式输入数据库。
为提高数据输入工作的效率和质量,应该针对具体的应用环境设计一个数据录入子系统,由计算机来完成数据入库的任务。
6.数据库运行和维护阶段数据库系统经过试运行合格后,数据库开发工作就基本完成,即可投入正式运行了。
在数据库系统的运行过程中,对数据库设计进行评价、调整、修改等维护工作是一个长期的任务,也是设计工作的继续和提高。
在数据库运行阶段,对数据库经常性的维护工作主要是由数据库管理员完成的,它包括数据库的转储和恢复、数据库的安全性与完整性控制、数据库性能的分析和改造、数据库的重组织与重构造。
当然数据库的维护也是有限的,只能做部分修改。
如果应用变化太大,重构也无济于事,说明此数据库应用系统的生命周期已经结束,应该设计新的数据库应用系统。
需要指出的是,设计一个完整的数据库应用系统是不可能一蹴而就的,它往往是上述6个阶段的不断反复,而且这个设计步骤既是数据库设计的过程,也包括了数据库应用系统的设计过程。
---------------------------------------------------------------最新资料推荐------------------------------------------------------ E-R模型转换为关系模型示例0、试述采用 E-R 方法进行数据库概念设计的过程。
答:采用 E-R 方法进行数据库概念设计,可以分成 3 步进行:首先设计局部 E-R 模式,然后把各局部 E-R 模式综合成一个全局的 E-R 模式,最后对全局 E-R 模式进行优化,得到最终的E-R模式,即概念模式。
1、某大学实现学分制,学生可根据自己情况选课。
每名学生可同时选修多门课程,每门课程可由多位教师主讲;每位教师可讲授多门课程。
其不完整的 E-R 图如图 1 所示。
(1)指出学生与课程的联系类型。
(2)指出课程与教师的联系类型。
(3)若每名学生有一位教师指导,每个教师指导多名学生,则学生与教师是如何联系?(4)在原 E-R 图上补画教师与学生的联系,并完善 E-R 图。
答:(1)(2)(3)(4)学生与课程联系类型是多对多联系。
课程与教师的联系类型是多对多联系。
学生与教师的联系类型是一对多联系。
完善本题 E-R 图的结果如图 2 所示。
1 / 16学生课程教师图 6.11 图 1 一个 E-R图图 6.12 完善后的 E-R图图 2 学生课程教师指导讲授选修mnmmn1 2、将如图 3 所示的 E-R 图转换为关系模式,菱形框中的属性自己确定。
答:本题的 E-R 图转换为如下的关系模式:单位(单位号,地址,电话)职工(职工号,姓名,性别,年龄,单位号)单位号职工号单位号地址年龄姓名电话性别单位职工D-E1m图 6.13 图 3 一个 E-R图 3、假定一个部门的数据库包括以下信息:(1)职工的信息:职工号、姓名、地址和所在部门。
(2)部门的信息:部门所有职工、部门名、经理和销售的产品。
E-R建模及关系表转换-例题习题-2014-s u b m i t t e d一、Consider the following information in an airport database●An airport is described by its name and the city that the airport locatesat●Each airplane has an unique registration number and also the date ofproduction as its descriptive attributes●Each airplane model is identified by a model number and has acapacity and a weight● A technician is characterized by an unique technician_id, his nameand his phone number●Each airport accommodates a number of airplane models, and anairplane model may appears in several airports; but some airports are not suitable for accommodaing several special plane models.●Each airplane is of a specific model, e.g. Boeing 737; and for eachmodel, there are more than one airplane being of it.●for each airport, there are some technicians working there, and eachtechnician must works at only one airport.●Each technician is responsible for one or more plane models, and eachplane model has at least one technician responsible for it●Each airplane is periodically tested by a number of technicians toensure that the airplane is still airworthy. A technician may testseveral airplanes each year, and sometimes a technician has no task for testing the airplanes.It is required that when a technician tests an airplane, the airplanemodel that he is responsible for is just the model that the airplanetested is of.The information, such as the test number, the testing date, thetesting result and the time spent on the test, is needed to describe atesting of the airplane(1) Design the E/R diagram for the airport database on the basis of the information mentioned aboveNote: the primary key of the entities, mapping cardinality of each relationship and participation of each entity to the relationship shouldbe described in the diagram. .(10 points)(2) Convert the E-R diagram to the proper relational schema, and give theprimary key of each relation schema by underlines.(10 points)Answers:(2) (10 points)实体airport归结为: airport(a-name, city);实体model归结为: model(m-num, weight, capacity);联系accommodate归结为: accommodate(a-name, m-num);实体airplane和联系be-of归结为:airplane(re-num, date, m-num); 实体technician、联系work归结为:technician(t-id, t-name, phone-num, a-name)联系test归结为:test(t-id, re-num, t-num, t-date, time, result)联系responsible归结为: responsible(t-id, m-num)二、 A university student database needs to store information aboutstudents, professors, projects, and departments. Consider the following information:●Each student has a SNo, a name, an age, and a degree program (e.g.M.S. or Ph.D.).●Each professor has a PNo, a name, an age, and a research specialty.●Each project has a project number, a starting date, an ending date, anda budget.●Each department has a department number, a department name, and amain office.●integrity constraints:a. A student studies in one (and only one) departmentb. A Professor works in one (and only one) departmentc.Each project must be managed by one and only one professor,and each professor must manage at least one project.d.Each project is worked on by some students, more than onestudent can participate(or work on) the same project, and somestudents may work on no projects.e.When a student work on a project, the professor managing thisproject must supervise the student’s work. One student maywork on several projects, so he may have several supervisors.(1) Design and draw an E/R diagram for this database that captures the information above .Note: mapping cardinality of each relationship and participation of each entity to the relationship should be described in the diagram. (2) Convert the E-R diagram to the proper relational schema, and give the primary key of each relation schema by underlines.Answers:(1)E-R diagram is as follows(2) the reduced tables are as follows:(a) student (SNo, name, age, degree-program, department-numbe r) Note: relationship study is reduced to this table(b) professor (PNo, name, age, research-area, department-number)Note: relationship works is reduced to this table(c) department (department-number, depart-name, main-officer)(d) project(project-number, starting-date, ending-date, budget, PNo) Note: relationship manage is reduced to this table(e) participate (SNo, project-number)(f) supervisor (SNo, PNo)solution2:(1) E-R diagram is as follows(2) the reduced tables are as follows:(a) student (SNo, name, age, degree-program, department-numbe r)Note: relationship study is reduced to this table(b) professor (PNo, name, age, research-area, department-number) Note: relationship works is reduced to this table(c) department (department-number, depart-name, main-officer)(d) project(project-number, starting-date, ending-date, budget, PNo) Note: relationship manage is reduced to this table(e) participate (SNo, project-number)(f) supervisor (SNo, Project-number, PNo)三、Notown Records company needs to store information about songs, albums(专辑)and musicians who perform on its albums in a database.Consider the following information:●Each musicians that records at company has an Id (which is unique), a name , anaddress, and a phone number.●Each instrument used in company has a name and an unique ID.●Each album recorded on the Notown label has a title, a copyright date, a format,and an album identifier.●Each song recorded at Notown has a title and an author, and each song can beidentified by its title.●An musician may play several instruments, and an instruments may be played byseveral musicians.●Each album has a number of songs on it, and each song belongs to only onealbum.●Each song is performed by one or more musicians, and a musician may perform anumber of songs.●Each album has exactly one musician who acts as its producer. A musician mayproduce several albums, but some musicians may have no albums.(1) Design the E/R diagram for hospital database on basis of the information mentioned above .(10 points)Note: mapping cardinality of each relationship and participation of each entity to the relationship should be described in the diagram.(2) Convert the E-R diagram to the proper relational schemas, and give the primary keys of each relation schemas by underlines. (10 points)四、 A hospital database needs to store information about doctors, patients,sickroom (病房), and departments (科室). Consider the following information●Each doctor has descriptive attributes of identifier number, name, age, andtechnical title).●Each patient has descriptive attributes of the number of medical records(病历) ,name, age, and sex●Each sickroom has descriptive attributes of the number of sickroom, the address ●Each department has descriptive attributes of name, address, telephone-number●Integrity constraints:a.Each doctor must belong to one (and only one) department; and for eachdepartment, there are more than one doctors belonging to it.b.Each patient is taken care of by one and only one responsible doctor; a doctormay be responsible for no patients, or only one patients, or more than onepatientsc.Each patient lives in one and only one sickroom; a sickroom may containmore than one patientsd.Each sickroom can be managed by more than one department; but for somedepartments, there are no sickrooms managed by them, while for otherdepartments, there are more than one managed sickroom.(1) Design the E/R diagram for hospital database on basis of the information mentioned above .(10 points)Note: mapping cardinality of each relationship and participation of each entity to the relationship should be described in the diagram.(2) Convert the E-R diagram to the proper relational schema, and give the primary key of each relation schema by underlines.(10 points)五、(20 points)A pharmacies database needs to store the information about thepharmaceutical companies(制药公司)and others. The relevant information is as follows:●Each pharmaceutical company is identified by its name and has a phone number.●Each pharmacy (药房) is identified by its name and has an address, and severalphone numbers.●For each drug, the trade name and formula must be recorded, and the trade nameidentifies a drug uniquely.●Each drug is developed by only one given pharmaceutical company, and onepharmaceutical company can develop several drugs and perhaps develops no dug now.●Each pharmacy sells several drugs and has a price for each. A drug could be soldby several pharmacies, and the price may vary from one pharmacy to another.●Pharmaceutical companies make contracts with pharmacies, but somepharmaceutical companies may have no contract. A pharmaceutical company can sign contracts with several pharmacies, and a pharmacy can also enter intocontracts with several pharmaceutical companies. Each contract is described by a start date, an end date and the content of the contract.(1) Design the E/R diagram for hospital database on basis of the information mentioned above. (10 points)Note: the mapping cardinality of each relationship and participation of each entity to the relationship should be described in the diagram.(2) Convert the E-R diagram to the proper relational schemas, and give the primary key of each relation schema by underlines. (10 points)六、(8 Points)A school is going to arrange a sports day for the students. A database tokeep track of participants and activities during the sports day is to be created.Consider the following information:(1). Participating persons. Each person has a number and a name. The person is identified by the number.(2). Teams. Each team has a number and a name. The team is identified by the number.(3). A team consists of several persons, and a person can be a member of several teams.A team must have at least one person, and a person may not participate in any team.(4). Activities, such as baseball or long jump. Each activity has a number, a name, and a starting time, and is identified by the number.(5). Participation in the activities. Both teams and individual persons can participate in more than one activities. Each person and each team must participate in at least one activity. Each activity can have many teams and many persons.Draw the E/R diagram for the database based on the information mentioned above.(8 Points)七、(10 points)Consider the following E/R diagram. Create the relational schema thatcaptures this E/R diagram. For every relation in your schema, specify the primary key of that relation.。