《数据库设计的基本步骤和方法ppt课件》由会员分享,可在线阅读,更多相关《数据库设计的基本步骤和方法ppt课件(63页珍藏版)》请在金锄头文库上搜索。
1、Database DesignDatabase DesignLiu Xiufeng Information and technology schoolObjectives for StudentsObjectives for Studentsv1 1Grasp the basic processes and method of DB Grasp the basic processes and method of DB designdesign ( (掌握数据库设计的基本步骤和方法掌握数据库设计的基本步骤和方法) )v2. Grasp the method of requirements ana
2、lysis2. Grasp the method of requirements analysis ( (掌握需求分析的方法掌握需求分析的方法) )v3 3Grasp the basic processes and method of Grasp the basic processes and method of conceptual designconceptual design ( (掌握概念结构设计的基本步骤和方法掌握概念结构设计的基本步骤和方法) ) Lecture OutlineLecture OutlineDB Design Overview1Basic Processes of
3、DB Design2Requirements Analysis3Conceptual Structure Design 4Conceptual Design 4Conclusion57.1 DB Design Overview7.1 DB Design OverviewThe definition of DB design数据库设计数据库设计 对于一个给定的应用环境,构造(设计)对于一个给定的应用环境,构造(设计)优化的数据库逻辑模式和物理结构,并据此建优化的数据库逻辑模式和物理结构,并据此建立数据库及其应用系统,使之能够有效地存储立数据库及其应用系统,使之能够有效地存储和管理数据,满足各种用
4、户的应用需求,包括和管理数据,满足各种用户的应用需求,包括信息管理要求和数据操作要求。信息管理要求和数据操作要求。Two points of DB DesignTwo points of DB Design1information management requirements (信息管理要求信息管理要求): store and manage all kinds of data objects in database2data manipulation requirements(数据操作要求数据操作要求): do some operations on data, eg. search ,add
5、 ,delete,alterT The Features of DB Designhe Features of DB Design1.Basic rules of constructing 1.Basic rules of constructing databsedatabse: : ( (数据库建设的基本规律数据库建设的基本规律) )v三分技术,七分管理,十二分基础数据三分技术,七分管理,十二分基础数据vManagement(Management(管理管理) ) 1.Manage DBAS Projects1.Manage DBAS Projects2.Manage business pro
6、cess of enterprise2.Manage business process of enterprisevBasic Data(Basic Data(基础数据基础数据) ) 1.collect1.collect、store store 2.Update 2.Update2.Combine data design and operation design:2.Combine data design and operation design: ( (数据设计和处理设计相结合数据设计和处理设计相结合) )数数数数据据据据库库库库设设设设计计计计应应应应用用用用系系系系统统统统设设设设计计计
7、计概念模型设计概念模型设计建立数据库建立数据库 数据分析数据分析逻辑数据库设计逻辑数据库设计物理数据库设计物理数据库设计 子模式设计子模式设计功能说明功能说明功能模型功能模型系统调试系统调试应用开发应用开发应用设计应用设计事务设计事务设计功能分析功能分析现实世现实世现实世现实世 界界界界结构和行为分离的设计结构和行为分离的设计T The Method of DB Designhe Method of DB Design1.Needs for the knowledge below:1.Needs for the knowledge below: Computer basic knowledge
8、Principle and Method of Software Engineer Method and Technique of programming designDatabase basic knowledgeDatabase Design technologyKnowledge in the specific field计算机的基础知识计算机的基础知识软件工程的原理和方法软件工程的原理和方法程序设计的方法和技巧程序设计的方法和技巧数据库的基本知识数据库的基本知识数据库设计技术数据库设计技术应用领域的知识应用领域的知识T The Method of DB Designhe Method
9、of DB Design2.Different kinds of methods including: New Orleans (新奥尔良法新奥尔良法)Method based on E-R Model(基于基于E-R模型的数据库设计方法模型的数据库设计方法)3NF Method(第三范式设计方法)第三范式设计方法)Object Definition Language Method(面象对象的设计方法面象对象的设计方法)Basic Processes of DB DesignPreparation for DB DesignPreparation for DB Design数据库设计的准备工作
10、数据库设计的准备工作Decide People Participating in DB Design(选定参加设计的人选定参加设计的人)1.系统分析人员、数据库设计人员系统分析人员、数据库设计人员(Analyser and Designer)自始至终参与数据库设计2. 用户和数据库管理员用户和数据库管理员 (users and DBA)主要参加需求分析和数据库的运行维护3.应用开发人员(应用开发人员( Application programmersApplication programmers)在系统实施阶段参与进来,负责编制程序和准备软硬件环境 DBAS Life CycleDBAS Lif
11、e CyclevDatabase Initial study( requirement analysis)Analyse the company situation, define problems and constrains, define objectives, define scope and boundariesvDatabase DesignCreate the conceptual designCreate the logical designCreate the physical designvImplementation and loadingInstall DBMS, cr
12、eate the database(s), load initial dataDBAS Life CycleDBAS Life CycleDBAS Life DBAS Life Cycle(contCycle(cont.).)vTesting and evaluationTest the databaseFine-tune(adjust) the databaseEvaluate the database and its application programsvOperationProduce the required information flowvMaintenance and evo
13、lutionIntroduce changesMake enhancements7.1.3数据库设计的基本步骤v数据库设计分数据库设计分6 6个阶段个阶段需求分析概念结构设计逻辑结构设计物理结构设计数据库实施数据库运行和维护 v需求分析和概念设计独立于任何数据库管理系统需求分析和概念设计独立于任何数据库管理系统 v逻辑设计和物理设计与选用的逻辑设计和物理设计与选用的DBMSDBMS密切相关密切相关Basic processes of DB DesignBasic processes of DB Design Physical Design Logic Design Mini-World Vie
14、w Requirements Collection and Analysis Conceptual Design Basic processes of DB DesignBasic processes of DB DesignvConceptual DesignHigh level description (often done ER model)Entity Relationship modelling and normalisationvDBMS software selectionvLogical designTranslate ER into DBMS data model Eg. t
15、ranslate model into definitions for tables, views.vSchema Refinement consistency, normalizationvPhysical designStorage structures - optimize performanceDistributed database design数据设计和处理设计同时进行数据设计和处理设计同时进行 Two Key points in DB DesignTwo Key points in DB Design 2.Carry Out The Two Jobs Simultaneously
16、 at All Stages, Consult Each Other, Supplement Each Other1.Combine Data Design and Manipulation Design CloselySchemas in DB DesignSchemas in DB Design数据库设计不同阶段形成的数据库各级模式数据库设计不同阶段形成的数据库各级模式7.2 Requirements of Analysis 7.2 Requirements of Analysis ( (需求分析需求分析) )vTasks of RA(Tasks of RA(需求分析的任务)需求分析的任务
17、)1.Defining requirements1.Defining requirements( (详细调查现实世界要处理的对象详细调查现实世界要处理的对象, 如组织、部门、企业如组织、部门、企业, 充分了解原系统充分了解原系统)2.Analyzing requirements(2.Analyzing requirements(明确用户的各种需求明确用户的各种需求) Inputs Inputs Outputs Outputs Processes Processes Data Storage Data Storage3.Decide the function and boundaries of
18、new system (3.Decide the function and boundaries of new system (确定确定新系统的功能新系统的功能) 同时充分考虑今后可能的扩充和改变同时充分考虑今后可能的扩充和改变Instance of Instance of AAvInputsInputsIndex pageIndex pageSearch stringSearch stringClicking on linksClicking on linksvOutputs Outputs Search resultsSearch resultsWeb pageWeb pagevProce
19、sses Processes Search database for search stringSearch database for search stringRetrieve web pageRetrieve web pagevData StorageData StorageKey points of RAKey points of RA需求分析的重点需求分析的重点vThe Critic Points of The Critic Points of Investigation:Data,OperationInvestigation:Data,Operation调查的重点是调查的重点是“数据
20、数据”和和“处理处理”vGet UsersGet Users Needs on DB Needs on DB(获得用户对数据库要求)(获得用户对数据库要求)Information Management Requirements( Information Management Requirements( 信息要求信息要求) )Operation Management Requirements(Operation Management Requirements(处理要求处理要求) )Security and Integrity Requirements(Security and Integrity
21、 Requirements(安全性与完整性要求安全性与完整性要求) )Difficulties of RADifficulties of RAvMake final users needs clear (确定用户最终需求确定用户最终需求)vReasons:Users lack for computer knowledge(用户缺少计算机知识用户缺少计算机知识)Designer lack for users professional knowledge (设计人员缺少用户的专业知识设计人员缺少用户的专业知识)vSolutions(解决方法解决方法):Designer should keep th
22、e constant and deep communication with users (设计人员必须不断深入地与用户进行交流设计人员必须不断深入地与用户进行交流)Often Used MethodsOften Used Methods(1)跟班作业(2)开调查会(3)请专人介绍(4)询问(5)设计调查表请用户填写(6)查阅记录Structured Analysis(结构化分析方法)从最上层的系统组织机构入手自顶向下、逐层分解分析系统Structured Analysis(结构化分析方法)1 1Any System can be Abstracted to be a Any System c
23、an be Abstracted to be a diagram below:diagram below:数据流数据流数据流数据流数据数据存储存储信息要求信息要求数据数据来源来源处理处理数据数据输出输出处理要求处理要求Structured Analysis(结构化分析方法)2 2Decompose Functions and Data(Decompose Functions and Data(分解处理功能和数据分解处理功能和数据) ) (1) (1) Decompose FunctionsDecompose Functions将处理功能的具体内容分解为若干子功能将处理功能的具体内容分解为若干子
24、功能 (2)Decompose Data(2)Decompose Data处理功能逐步分解同时,逐级分解所用数据,形成若干层次的数处理功能逐步分解同时,逐级分解所用数据,形成若干层次的数据流图据流图 (3)expression methods(3)expression methods(表达方法表达方法) )处理逻辑:用判定表或判定树来描述处理逻辑:用判定表或判定树来描述数据:用数据字典来描述数据:用数据字典来描述3 3Get Confirmation of usersGet Confirmation of users 将分析结果再次提交给用户,征得用户的认可将分析结果再次提交给用户,征得用户的
25、认可Procedure of RAProcedure of RA( (需求分析过程需求分析过程) )7.2.3 Data Dictionary7.2.3 Data Dictionary( (数据字典数据字典) )v1.Purpose of Data Dictionary1.Purpose of Data Dictionary 进行详细的数据收集和数据分析所获得的主要结果v2.Content of Dictionary2.Content of DictionaryData Item(Data Item(数据项数据项) )Data Structure(Data Structure(数据结构数据结构
26、) )Data Flow(Data Flow(数据流数据流) )Data Storage(Data Storage(数据存储数据存储) )Procedure of Operation)Procedure of Operation)处理过程处理过程) ) Data Item(Data Item(数据项数据项) )v Atomic item(Atomic item(数据项是不可再分的数据单位)v Description of Data itemDescription of Data item 数据项描述 数据项名,数据项含义说明,别名, 数据类型,长度,取值范围,取值含义,与其他数据项的逻辑关系,
27、数据项之间的联系 Data structureData structure( (数据结构数据结构) )vSpecify the data Specify the data itemsitemss s relationship relationship ( (数据结构反映了数据之间的组合关系。数据结构反映了数据之间的组合关系。) )vConsist of several data items or data structure , Consist of several data items or data structure , or two things togetheror two thin
28、gs together (一个数据结构可以由若干个数据项组成,也可以由若干(一个数据结构可以由若干个数据项组成,也可以由若干个数据结构组成,或由若干个数据项和数据结构混合组成。)个数据结构组成,或由若干个数据项和数据结构混合组成。)v Description of Data StructureDescription of Data Structure 数据结构描述数据结构名,含义说明,数据结构描述数据结构名,含义说明, 组成组成: :数据项或数据结构数据项或数据结构 Data Flow(Data Flow(数据流数据流) )v moving route of data structure in
29、 systemmoving route of data structure in system( (数据流是数据结构在系统内传输的路径。数据流是数据结构在系统内传输的路径。v Description:Description: 数据流描述数据流描述 数据流名,说明,数据流来源,数据流名,说明,数据流来源, 数据流去向,组成数据流去向,组成: :数据结构,数据结构, 平均流量,高峰期流量平均流量,高峰期流量 Data Storage(Data Storage(数据存储数据存储) )vPlace for data to stay or to be stored, also input and out
30、put data flow(数据存储是数据结构停留或保存的地方,也是数据流的来源和去向之一。)vDescription: 数据存储描述数据存储名,说明,编号,输入的数据流 ,输出的数据流 ,组成:数据结构,数据量,存取频度,存取方式 Procedure of operationProcedure of operation( (处理过程处理过程) )vDecision Diagram or Decision Tree used to deal with logics (具体处理逻辑一般用判定表或判定树来描述)vDescription:处理过程描述处理过程名,说明,输入:数据流, 输出:数据流,处
31、理:简要说明Requirements AnalysisRequirements Analysis( (需求分析需求分析) )分析用户活动产生,产生分析用户活动产生,产生业务流程图业务流程图确定系统范围,产生确定系统范围,产生系统范围图系统范围图分析用户活动涉及的数据,产生分析用户活动涉及的数据,产生数据流图数据流图分析系统数据,产生分析系统数据,产生数据字典数据字典Summary for requirements AnalysisSummary for requirements Analysisv设计人员应充分考虑到可能的扩充和改变,使设计易于设计人员应充分考虑到可能的扩充和改变,使设计易于更
32、改,系统易于扩充更改,系统易于扩充 v必须强调用户的参与必须强调用户的参与7.3 7.3 Conceptual Design Using the ER Model Conceptual Design Using the ER Model ( (用用ERER图进行图进行概念结构设计概念结构设计) )vDesign choices:Should a concept be modeled as an entity or an attribute?Should a concept be modeled as an entity or a relationship?Identifying relatio
33、nships: Binary or ternary? vNote constraints of the ER Model:A lot of data semantics can (and should) be captured.But some constraints cannot be captured in ER diagrams.Well refine things in our logical (relational) designAbstract Methods Abstract Methods v1.1.分类分类(Classification, is member of)(Clas
34、sification, is member of) Entity Set ( Entity Set (Student,Teacher,CourseStudent,Teacher,Course) )v2.2.聚集聚集(Aggregation, is part of)(Aggregation, is part of) Attribute(Student:Sno,Sname,Ssex,SageAttribute(Student:Sno,Sname,Ssex,Sage) )v3.3.概括概括(Generalization, is subset of)(Generalization, is subset
35、 of)vSuperclassSuperclassvSubclassSubclassStudentundergraduategraduateExample of ER ModelEntity SetRelationship SetAttribute老师学生教mn学号姓名专业班级职称性别姓名职号Categorization of Categorization of AttibutesAttibutes( (属性的分类属性的分类) )v基本属性和复合属性基本属性和复合属性v单值属性和多值属性单值属性和多值属性v多值属性的处理多值属性的处理将原来的多值属性用将原来的多值属性用 几个新的单值属性来表示
36、几个新的单值属性来表示 将原来的多值属性用将原来的多值属性用 一个新的实体类型表示一个新的实体类型表示 v导出属性导出属性图图5.4 5.4 地址属性的层次结构地址属性的层次结构邮政编码邮政编码省(市)省(市)名名地地 址址区区 名名街街 道道家庭地址家庭地址门牌号码门牌号码多值属性的表示多值属性的表示零件编码零件编码零零 件件零件名零件名供应商供应商规格规格进货价格进货价格销售价格价销售价格价格格图图5.8 5.8 导出属性的表示导出属性的表示工号工号职职 工工姓名姓名基本工资基本工资奖金奖金房租房租实发工资实发工资Operation on ER ModelOperation on ER M
37、odel(ER(ER模型上的操作模型上的操作) )教师号教师号姓名姓名出生日期出生日期职务职务工资工资奖金奖金教师教师(a)教师号教师号姓名姓名出生日期出生日期教师不变信息教师不变信息职务职务工资工资奖金奖金教师号教师号教师变动信息教师变动信息(b)图图 实体类型的垂直实体类型的垂直分裂分裂Design of local ER ModelDesign of local ER Model设计局部设计局部ERER模式模式 需求分析结果需求分析结果确定局部结构范围确定局部结构范围实体定义实体定义联系定义联系定义属性分配属性分配还有局部还有局部结构待分结构待分析析有有无无进入全局进入全局ERER模式设
38、计模式设计图 局部ER模式设计确定属性的原则: 属性应该是不可再分解的语义单位;实体与属性之间的关系只能是1:N的。属性分配的原则: 当多个实体类型用到同一属性时,一般把属性分配给那些使用频率最高的实体类型,或分配给实体值少的实体类型。 有些属性不宜归属于任一实体类型,只说明实体之间联系的特性 An Example of An Example of IntergrationIntergration of E-R Model of E-R ModelvLocal ER Model of studentsLocal ER Model of studentsvLocal ER Model of Co
39、ursesLocal ER Model of CoursesvIntergrationIntergration of ER Model of ER ModelWhole ER Model(Whole ER Model(全局全局 ERER模式模式) )无无全局全局ERER模式设计模式设计 局部局部ER模式模式确定公共实体类型确定公共实体类型合并两个局部合并两个局部ER模式模式检查并消除冲突检查并消除冲突还有未合还有未合并的局部并的局部模式模式有有还有冲突吗还有冲突吗有有1.Attribute conflict1.Attribute conflict2.Structure conflict2.St
40、ructure conflict3.Name conflict:3.Name conflict:Optimization of Whole ER ModelOptimization of Whole ER Model全局全局ERER模式的优化模式的优化vUnite entity setsUnite entity sets ( (实体类型的合并实体类型的合并) )vEliminate redundant attributesEliminate redundant attributes ( (冗余属性的消除冗余属性的消除 ) )vEliminate redundant relationshipEl
41、iminate redundant relationship ( (冗余联系的消除冗余联系的消除) )A A)Unite EntitiesUnite Entities( (合并实体合并实体) )v一般一般1:11:1联系的两个实体可以合并为一个实体联系的两个实体可以合并为一个实体v如果两个实体在应用中经常需要同时处理,也可如果两个实体在应用中经常需要同时处理,也可考虑合并考虑合并例如病人和病历,如果实际中通常是查看病人例如病人和病历,如果实际中通常是查看病人时必然要查看病历,可考虑将病历合并到病人时必然要查看病历,可考虑将病历合并到病人实体中实体中减少了联接查询开销,提供效率减少了联接查询开销
42、,提供效率B B)eliminate redundant eliminate redundant AttributesAttributes(消除冗余属性)(消除冗余属性)v分分ERER图中一般不存在冗余属性,但集成后可能产图中一般不存在冗余属性,但集成后可能产生冗余属性生冗余属性例如,教育统计数据库中,一个分例如,教育统计数据库中,一个分ERER图中含有高校毕业图中含有高校毕业生数、在校学生数,另一个分生数、在校学生数,另一个分ERER图中含有招生数、各年图中含有招生数、各年级在校学生数级在校学生数每个分每个分ERER图中没有冗余属性,但集成后图中没有冗余属性,但集成后“在校学生数在校学生数”
43、冗余,应消除冗余,应消除Logic DB DesignLogic DB DesignvConverting ER to RelationalFairly analogous structureBut many simple concepts in ER are subtle to specify in relationsER to RelationER to RelationvEntity sets to tables. CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot INTEGER, PRIMARY KEY (ssn)ssnn
44、amelot123-22-3666Attishoo48231-31-5368Smiley22131-24-3650Smethurst35EmployeesssnnamelotRelationship Sets to TablesRelationship Sets to TablesvIn translating a many-to-many relationship set to a relation, attributes of the relation must include:1) Keys for each participating entity set (as foreign ke
45、ys). This set of attributes forms a superkey for the relation.2) All descriptive attributes.CREATE TABLE Works_In( ssn CHAR(1), did INTEGER, since DATE, PRIMARY KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments)ssndidsince123-22-3666511/1/91123-22-36665
46、63/3/93231-31-5368512/2/92Review: Key ConstraintsReview: Key ConstraintsvEach dept has at most one manager, according to the key constraint on Manages.Translation to relational model?Many-to-Many1-to-11-to ManyMany-to-1dnamebudgetdidsincelotnamessnManagesEmployeesDepartmentsTranslating ER with Key C
47、onstraintsTranslating ER with Key ConstraintsvSince each department has a unique manager, we could instead combine Manages and Departments.CREATE TABLE Manages( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, CREATE TABLE Dept_Mgr( did INTEGER, dname
48、 CHAR(20), budget REAL, ssn CHAR(11), since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees)Vs.dnamebudgetdidsincelotnamessnManagesEmployeesDepartmentsReview: Participation ConstraintsReview: Participation ConstraintsvDoes every department have a manager?If so, this is a participatio
49、n constraint: the participation of Departments in Manages is said to be total (vs. partial).Every did value in Departments table must appear in a row of the Manages table (with a non-null ssn value!)lotnamednamebudgetdidsincenamednamebudgetdidsinceManagessinceDepartmentsEmployeesssnWorks_InParticipa
50、tion Constraints in SQLParticipation Constraints in SQLvWe can capture participation constraints involving one entity set in a binary relationship, but little elseCREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11) NOT NULL, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn)
51、REFERENCES Employees)Physic DesignPhysic Designv设计数据库的物理结构设计数据库的物理结构为关系模式选择存取方法设计数据库的存储结构v物理设计的考虑物理设计的考虑查询时间效率存储空间维护代价v物理设计依赖于给定的计算机系统物理设计依赖于给定的计算机系统1.Select access method1.Select access methodv存取方法:数据的存取路径存取方法:数据的存取路径例如图书查询v存取方法的选择目的是加快数据存取的速度存取方法的选择目的是加快数据存取的速度索引存取方法聚簇存取方法散列存取方法可以使用什么样的存取方可以使用什么样的
52、存取方法依赖于具体的法依赖于具体的DBMS2.Design storage structure of Database2.Design storage structure of Databasev确定数据的存放位置确定数据的存放位置针对应用环境和DBMS特性,合理安排数据存储位置表和索引可考虑放在不同的磁盘上,使查询时可以并行读取日志文件和备份文件由于数据量大,而且只有恢复时使用,可放到磁带上v确定系统配置确定系统配置系统初始参数不一定适合应用并发用户数、同时打开的数据库对象数、缓冲区分配参数、物理块的大小等Implement of DatabaseImplement of Databasev
53、建立实际的数据库结构建立实际的数据库结构CREATE TABLECREATE INDEXv初始数据装入初始数据装入v安全性设计和故障恢复设计安全性设计和故障恢复设计v应用程序的编码和调试应用程序的编码和调试Operation and MaintainOperation and Maintainv试运行试运行根据初始数据对数据库系统进行联调执行测试:功能、性能v维护维护数据备份和恢复数据库安全性控制和完整性控制数据库性能的分析和改造数据库的重组织Useful LinksUseful Linksv人大人大数据库系统概论数据库系统概论国家精品课程国家精品课程vThe database course
54、in The database course in harvardharvard university universityvThe Database and Information Systems The Database and Information Systems Laboratory on UIUCLaboratory on UIUCConclusionConclusionv1.1.数据库设计需要综合多种知识,通常由有经验数据库设计需要综合多种知识,通常由有经验 的系的系统分析人员来进行统分析人员来进行v2.2.搞清楚应用系统的业务逻辑是设计的关键,包括系统的搞清楚应用系统的业务逻辑是设计的关键,包括系统的数据要求和处理要求数据要求和处理要求v3.3.在业务的基础上选择合适的技术在业务的基础上选择合适的技术ConclusionConclusion