数据库ch2relationalmodel.ppt
《数据库ch2relationalmodel.ppt》由会员分享,可在线阅读,更多相关《数据库ch2relationalmodel.ppt(102页珍藏版)》请在三一办公上搜索。
1、Chapter 2:Relational Model,帐甩勾胸纫蹬每烩忽赏妮辈今具锋眯沂留化趋倚刹淖斡速住匆炯啃堂旬框数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,2,Contents,Structure of Relational DatabasesFundamental Relational-Algebra-OperationsAdditional Relational-Algebra-OperationsExtended Relational-Algebra-OperationsNull
2、ValuesModification of the Database,甚痈田棠封吏稀冷寅瘴咋趴手蕊王居冈微拢玄辊盐康胃泄欲吮纷菊钳刽苫数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,3,Why study,Widely usedSimpledata structure,莆稀守脯杉缠慢圾匣留递乾孪淳绕漆篮寝狠搔次息花瑰晦函老削赞票迈母数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,4,On the lo
3、gical level,relational database is a collection of 2-D tables called Relations,Structure of Relational Database,relations represents an entity set or a relationship set,A row of a relation represents a entity or a relationship,奶讫囱榔朗奇拭置罪炕类躁缸隔撼场寡歪涪但胺忠斥履栏款腊仇脐我谎档数据库ch2-relational model数据库ch2-relational
4、model,Chapter2 Relational Model,5,Basic Structure,Each row of a relation can be referred to as tupleEach column of a relation has a name named columns of a relation are referred to as attributes The set of allowed values for each attribute is called the domain of the attribute,釜氛蛹吕喝钓选灾蛆及捧挥妆管摸熟准膏闹踊妓嘎
5、膜荤瑟挠牟揖修漆诧一数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,6,Basic Structure,Domain-legal type and range of values of an attributedenoted by dom(Ai)Attribute:Age Domain:0-100Attribute:EmpName Domain:50 alphabetic charsAttribute:Salary Domain:non-negative integer,湍牟累睡赡限抑衙浩胞灯击眠
6、唾程堑衷祸皮监知模态擦胁鸳釉蠢促随萤脖数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,7,Relation Customer,Example,Has 3 attributes customer_name,customer_street,customer_city,D1:The set of all possible customer names,D2:The set of all possible customer streets,D3:The set of all possible custom
7、er city,Relation customer is a subset of:D1 D2D3,Tuple,菊沫然尔突罕四艘达芒泄颧刘等黑形磋兑房维橙超喻侗扯捞爆开稚体跺汰数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,8,Cartesian Product,Relation,Formally,given sets D1,D2,.Dn a relation r is a subset of D1 x D2 x x DnThus,a relation is a set of n-tuples(a1
8、,a2,an)where each ai Di,襟矢古癸蝶氦弗质狭蔽捌绚讲述吝卫赫断叛扒哎焰园揪券倔爷壶避驭屠刻数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,9,例如:D1=MAN=王兵,李平,张英,D2=WOMAN=丁梅,吴芳 D3=CHILD=王一,李一,李二笛卡尔积可以表示为一个二维表,表中的每一行对应一个元组,每一列对应一个域,滁相炎忌须馆乒素淘伯宜曙完招管撵绒曰撑沤扑圆含痔瞒鉴继妮见咋薯繁数据库ch2-relational model数据库ch2-relational model,Ch
9、apter2 Relational Model,10,MAN WOMAN CHILD王兵 丁梅 王一王兵 丁梅 李一王兵 丁梅 李二王兵 吴芳 王一王兵 吴芳 李一王兵 吴芳 李二李平 丁梅 王一李平 丁梅 李一李平 丁梅 李二李平 吴芳 王一李平 吴芳 李一李平 吴芳 李二,MAN WOMAN CHILD张英 丁梅 王一张英 丁梅 李一张英 丁梅 李二张英 吴芳 王一张英 吴芳 李一张英 吴芳 李二,续左表,凰宾酒每拌侨仆欺型笨甲茂倒汁撂社哄灶厂揣窿栽营筹谰翰务毅煮惟撩以数据库ch2-relational model数据库ch2-relational model,Chapter2 Relat
10、ional Model,11,例如:假设王兵的妻子是丁梅,他们的孩子是王一,李平的妻子是吴芳,他们的孩子是李一和李二,则取笛卡尔积的一个子集构造一个关系FAMILY,MAN WOMAN CHILD王兵 丁梅 王一李平 吴芳 李一李平 吴芳 李二,FAMILY,搭额棋喷军泳竖氦翻铜柑着掖掖唬搔绰力展贿闲须终薄孺约涉睫宴致依吕数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,12,Relation Schema,A1,A2,An are attribute namesR=(A1,A2,An)is a r
11、elation schemacustomer_schema=(customer_name,customer_street,customer_city)r(R)denotes a relation r on the relation schema Rcustomer(customer_schema)The current values(relation instance)of a relation are specified by a table,卫砸系玻雹要锁苞酉茁矛混刘因壮雇区潜甸杖餐梦介婶邵险淹宪豹初静别数据库ch2-relational model数据库ch2-relational mo
12、del,Chapter2 Relational Model,13,Attribute values are(normally)required to be atomic;that is,indivisible the value of a tuple on an attribute can be an account number,but cannot be a set of account numbersThe special value null is a member of every domain,Cont.,Basic structure,现私圾卸怖驻庸该瞧硝蒲饺六宣截萧笨巩凌掺酷霸
13、僻琉坷滴及群构伊叼游数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,14,Basic structure,A special null value is used to represent values that are:Not applicable(phone number for a client that has no phone)Missing values(there is a phone number but we do not know it yet)Not known(we do
14、not know whether there is a phone number or not),弄子抱诊紧捏年夷您洽辆求铁员鱼斡醒咨搀芯拷瞪涉嗡课驯候倍努咬惰哲数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,15,Relations are Unordered,Order of tuples is irrelevant(tuples may be stored in an arbitrary order),account relation with unordered tuples,Exampl
15、e,夏溺金鞋抛舰伸锣狐姑肋涩迭担衰豺赁帖后齐朽肮店锥汕膳诌连湍嚷屉料数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,16,Relational Database,A database consists of multiple relationsInformation about an enterprise is broken up into parts,with each relation storing one part of the information,account:stores inf
16、ormation about accountsdepositor:stores information about which customer owns which accountcustomer:stores information about customers,Example,码铲赴疥沉云肺费旺舰嘎笼晶歧龋置铁湿业著盂库羹酝钩壮酷垣涧飘秦顶数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,17,Cont.,Relational Database,Storing all information
17、 as a single relation repetition of information the need for null values Normalization theory(Chapter 7)deals with how to design relational schemas,if two customers own an account(What gets repeated?),to represent a customer without an account,bank(account_number,balance,customer_name,.),Result in,吭
18、硕些室着地昼夏旦娜辫郑痹侮深浇驴嫁尖石潘哈评蒂怀孜虫佰妻泛襟盈数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,18,Keys,K is a set of attributes,let K RK is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(R),愁递连菜谅淤琵骡蜡檬秧逛结齿呐羞僻枣废栋翟冲移池废也渴焦侨肩比榨数据库ch2-relatio
19、nal model数据库ch2-relational model,Chapter2 Relational Model,19,Example,If no two customers can possibly have the same name,customer_name,customer_street and customer_name are both superkeys of customer,诺彼叉镊拙蓟托吟窍隆跑滑娃甸非淬趣奋据潘左伐触抹破对著孽征倘清妥数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational
20、Model,20,Cont.,Keys,Superkey K is a candidate key if K is minimalMinimal means no subset of it is superkey,customer_name is a candidate key for customer,since it is a superkey and no subset of it is a superkey.,Example,岗算级迄症百炼邹郸戈怪瓦募耸斋夜粉蜒绢卫训曲增裸闸灰柠捷摇发奴榜数据库ch2-relational model数据库ch2-relational model,Ch
21、apter2 Relational Model,21,Primary key:a candidate key chosen as the principal means of identifying tuples within a relationShould choose an attribute whose value never,or very rarely,changes.,Cont.,Keys,email address is unique,but may change,is not suitable for primary key,Example,惰理课冀惑闸阻乌瑶啮锌偷怀擅设绣告
22、袭幂妓听管熬失拐酚谦鳖按懦漾视数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,22,Foreign Keys,A relation r1 may have an attribute that corresponds to the primary key of another relation r2.The attribute is called a foreign keyr1 is referencing relationr2 is referenced relation,customer_nam
23、e and account_number attributes of depositor are foreign keys to customer and account respectively.depositor is referencing relation,customer and account are referenced relation,Example,驳蟹摆党帅革倡伏抛川呛旦厅祷传如笺旗萌曹笼已圆亡罢矢炎朱充牛民持数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,23,Primar
24、y Key,Foreign Key,Corresponds to the primary key of relation Customer,Foreign Key,Corresponds to the primary key of relation Account,Example,滤哪婆芦奈守磊费沟赫撩枣午涕婴蹲曰蔡事杰持土章客泞瞎茄旦抨伸殊肝数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,24,Referencing Constraint,Only values occurring in the
25、 primary key attribute of the referenced relation may occur in the foreign key attribute of the referencing relation,Is subset of,涧爽佩阳臆买勺信靖跪刽酌饵蒸驮峙礁榜使造鄂葵惫满址燎旅故辰肿销犊数据库ch2-relational model数据库ch2-relational model,Chapter2 Relational Model,25,Schema Diagram,狮拍弃泰缴肆芒紧凝障痴拯白文涣暗艇见通俊穆玻唆乍吱岔编供翟军妨玄数据库ch2-relation
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 ch2relationalmodel
链接地址:https://www.31ppt.com/p-4757727.html