数据库原理英文课件Chapter3TheRelationalDataModel.ppt
《数据库原理英文课件Chapter3TheRelationalDataModel.ppt》由会员分享,可在线阅读,更多相关《数据库原理英文课件Chapter3TheRelationalDataModel.ppt(52页珍藏版)》请在课桌文档上搜索。
1、1,Database Principles,2,Chapter 3The Relational Data Model,Relational ModelFunctional Dependencies,3,Contents,3.1 Basics of the Relational Model3.3 From E/R diagrams to Relational Designs3.5 Functional Dependencies3.7 Design of Relational Database SchemasReading GuideExercise,4,The things you should
2、 know,The basic principle of relational database is proposed by E.F.Codd in 1970.The first RDBMS production is System RThe most popular RDBMSDB2,Oracle,Ingres,Sybase,Informix,5,3.1 Basic of the Relational Model,The relational model gives us a single way to represent data:as a two-dimensional table c
3、alled a relation.,6,Attributes(属性)Attributes of a relation serve us as names for the columns of the relation.Usually,the attributes describes the meaning of entries in the column below.,7,Schemas(模式)The name of a relation and the set of attributes for a relation is called the schema for that relatio
4、n.We show the schema for the relation with the relation name followed by a parenthesized list of its attributes.,8,Tuples(元组)The rows of a relation,other than the header row containing the attributes,are called tuple.For example:Relations,however,are sets of tuples,and it is impossible for a tuple t
5、o appear more than once in a given relation.,9,Domains(域)The relational model requires that each component of each tuple be atomic;that is,it must be of some elementary type such as integers or string.Each attributes of a relation has particular elementary type,thus domain is decided.,10,Equivalent
6、Representations of a RelationThe attributes of the relation can be reordered without change the relation.,11,Relation Instance(关系实例)A relation about movies is not static;rather,relations change over time.It is not common for the schema of a relation to change.We shall call a set of tuples for a give
7、n relation an instance of that relation.,12,An Example of Relation Instance,Relation:Person(Name,Address,Telephone)Relation Instance:NameAddressTelephoneBob123 Main St555-1234Bob128 Main St555-1235Pat123 Main St555-1235Harry456 Main St555-2221Sally456 Main St555-2221Sally456 Main St555-2223Pat12 Sta
8、te St555-1235,13,More,Relation(Instance)=a set of tuplesDatabase=collection of relationsRelation schema=relation name+attributesExample:Movies(title,year,length,fileType)Database schema=a set of all relation schemasMovies(Title,Year,Length,FileType)Star(Name,Age)Studio(StudioName,Addr),14,Name Addr
9、Tel N1 A1 T1 N2 A2 T2 N3 A3 T3 N4 T4 N5 T5 T6 T7,Name Addr Tel N1 A1 T1 N1 A1 T2 N1 A1 T3.N1 A1 T7 N1 A2 T1 N1 A3 T1 N2 A1 T1,Tuple,Domain,Component,Attribute,15,Integrity Constrain of Relations,Entity ConstrainThe attributes belong to key can not be set as NULL.Reference ConstrainForeign Key:an non
10、-key attribute A in R is a key in S,then the A is called a foreign key of R.The value of foreign key can only be NULL or same as what is in S.User-define ConstrainUsers define the constrains themselves.,16,补充:关系的完整性,实体完整性参照完整性用户定义完整性 实体完整性和参照完整性是关系模型必须满足的,被称作关系的不变性,由关系数据库系统自动支持,17,实体完整性,规则:若属性A是基本关系
11、R的主属性,则属性A不能取空值说明:基本关系的主码中的任何属性都不能取空值,而不仅是主码整体不能取空值依据:现实世界的实体是唯一可分的例:学生(学号,姓名,性别,专业号,年龄)课程(课程号,课程名,学分)选修(学号,课程号,成绩),18,例:学生实体与专业实体间的关系:学生(学号,姓名,性别,专业号,年龄)专业(专业号,专业名)关系参照图,例:学生,课程,学生与课程之间的多对多联系:学生(学号,姓名,性别,专业号,年龄)课程(课程号,课程名,学分)选修(学号,课程号,成绩)关系参照图,参照关系,学生关系专业关系,专业号,学生关系 选修关系课程关系,学号,课程号,参照完整性,主码?外码?,19,
12、参照完整性,定义:外码设F是参照关系R的一个或一组属性,但不是R的码,若F与被参照关系S的主码相对应,则称F是R的外码(详细定义见教材P54)规则:参照关系R中每个元组在外码F上的值必须为:或者取空值(F的每个属性值均为空值)或者等于S中某个元组的主码值,例:学生(学号,姓名,性别,专业号,年龄,班长),参照关系,被参照关系,外码,20,用户定义完整性,用户定义的、具体应用中的数据必须满足的约束条件成绩:0100之间身份证、身份证和生日对应关系,21,3.2 From E/R Diagrams to Relation,From Entity Sets to RelationSimplest a
13、pproach(not always best):convert each E.S.to a relation.Create a relation of the same name and with the same set of attributes.,22,Movies(title,year,length,filmType)Stars(name,address)Studios(name,address),Example,23,From E/R Relationships to RelationRelationships in the E/R model are also represent
14、ed by relations.The relation for a given relationship R has the following attributes;For each entity set involved in relationship R,we take its key attributes as part of the schema of the relation for R.If the relationship has attributes,then these are also attributes of relation R.,24,Example:,Owns
15、(title,year,studioname),Stars-in(title,year,starName),25,E-R图向关系模型的转换原则,一个实体转换为一个关系模式,实体的属性就是关系的属性,实体的码就是关系的码对实体间的联系一个1:1联系可以转换为一个独立的关系模式,也可以与任意对应的关系模式合并一个1:n联系可以转换为一个独立的关系模式,也可以与n端对应的关系模式合并一个m:n联系转换为一个关系模式三个或三个以上实体间的一个多元联系可以转换为一个关系模式具有相同码的关系模式可以合并,补充:,26,如公司部门管理系统的E-R图及其转换成的关系模式,部门,项目,职工,电话,包括,承担,n
16、,1,n,1,办公室号,面积,项目号,预算费,参与,m,n,办公室,包含,1,n,包括,n,1,部门号,预算费,领导人职工号,电话号码,说明,职工号,姓名,办公电话,分担任务,部门(部门号,部门预算费,领导人职工号)职工(职工号,姓名,办公电话,部门号)办公室(办公室号,面积,部门号)项目(项目号,项目预算费,部门号)电话(电话号码,说明,办公室号)项目承担情况(职工号,项目号,分担任务),27,Exercise,Required:Convert the E-R diagram you designed in last exercise into a relational database s
17、chema.,28,3.5 Functional Dependencies,Definition of Functional Dependency(函数依赖)X-A is an assertion about a relation R that whenever two tuples of R agree on all the attributes of X,then they must also agree on the attribute A.Say“X-A holds in R.”ConventionX,Y,Z represent sets of attributes;A,B,C,rep
18、resent single attributes.,酞昧戚槛纠默厅宾帜点苑仅剪莽杨范炒伸黎悸帅摔贮尸懦敌鲤撂险编蹈秤数据库原理 英文课件Chapter3-The Relational Data Model数据库原理 英文课件Chapter3-The Relational Data Model,29,ExampleMovies(title,year,length,filmType,studioName,starname)We can assert the three dependencies:title,year-lengthtitle,year-filmTypetitle,year-studi
19、oName,导毙蕉拇碴梆萍至姑泡酸懈伪别娃甘桩赃寨峡所萝奄韵揉陵躺宜藐童愤缕数据库原理 英文课件Chapter3-The Relational Data Model数据库原理 英文课件Chapter3-The Relational Data Model,30,FDs With Multiple AttributesNo need for FDs with multiple attribute on right.But sometimes for convenient we can combine them.Example:title,year-length title,year-filmTyp
20、e title,year-starName become title,year-length,filmType,starNameMultiple attribute on left may be essential.Example:title,year-length,亲移炕困拼昼共腊河功干陶凰矾儡担娄备脱纯幻秆芦讣咀赞狼矾医带撤戍数据库原理 英文课件Chapter3-The Relational Data Model数据库原理 英文课件Chapter3-The Relational Data Model,31,Trivial DependenciesA functional dependenc
21、y A1A2An-B is said to be trivial(平凡)if B is one of the As,otherwise is said to be nontrivial(非平凡).Example:Suppose Functional Dependencies title,year-title is a trivial dependency.,厨话蛋梨流巷赋巢辊项屯圈阴渴腊袱毯劣靴洞动感陕者个顺吗岗降环锡胶数据库原理 英文课件Chapter3-The Relational Data Model数据库原理 英文课件Chapter3-The Relational Data Model
22、,32,Transitive(传递)Functional DependenciesSuppose we have a relation R with three attributes A,B,and C,the FDs A-B and B-C both hold for R.Then it is easy to see that the FD A-c also holds for R,So C is said to depend on A transitively,via B,绥碟卧静妥首躬裂皱感拢球岔岗西帘漾恤更余蒲麦盾径详亥晤线逗欲芥令数据库原理 英文课件Chapter3-The Rela
23、tional Data Model数据库原理 英文课件Chapter3-The Relational Data Model,33,Keys of Relations from FDs viewWe say a set of one or more attributes A1,A2,An is a key for relation if:Those attributes functionally determine all other attributes of the relation.That is,it is impossible for two distinct tuples of R
24、to agree on all of A1,A2,An.No proper subset of A1,A2,An functionally determines all other attributes of R;i.e.,a key must be minimal,迪图辉箕延蛀沏耸咙腰膳俊懂铁厨巾耻袜缨辗没付绎刺撬拿蕴风虫诞牙遇数据库原理 英文课件Chapter3-The Relational Data Model数据库原理 英文课件Chapter3-The Relational Data Model,34,ExampleAttributes title,year,starName form
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 原理 英文 课件 Chapter3TheRelationalDataModel
链接地址:https://www.desk33.com/p-602125.html