數(shù)據(jù)庫教學課件:第2章 數(shù)據(jù)模型_第1頁
數(shù)據(jù)庫教學課件:第2章 數(shù)據(jù)模型_第2頁
數(shù)據(jù)庫教學課件:第2章 數(shù)據(jù)模型_第3頁
數(shù)據(jù)庫教學課件:第2章 數(shù)據(jù)模型_第4頁
數(shù)據(jù)庫教學課件:第2章 數(shù)據(jù)模型_第5頁
已閱讀5頁,還剩398頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

第2章數(shù)據(jù)模型2.1綜述2.2經(jīng)典數(shù)據(jù)模型回顧2.3面向?qū)ο髷?shù)據(jù)模型2.4可擴展/對象-關系數(shù)據(jù)模型2.5半結構化數(shù)據(jù)模型2.6數(shù)據(jù)的語義2.7數(shù)據(jù)模型統(tǒng)一框架:本體2.1綜述

為什么需要數(shù)據(jù)模型?如何描述數(shù)據(jù)模型?數(shù)據(jù)模型有哪些內(nèi)容?如何評價數(shù)據(jù)模型?數(shù)據(jù)模型為什么有層次性?數(shù)據(jù)模型的未來?為什么需要數(shù)據(jù)模型?數(shù)據(jù)庫中的數(shù)據(jù)是有組織的,即不只有數(shù)據(jù),還包括描述數(shù)據(jù)的部分,通常稱為數(shù)據(jù)模式(schema)早期的數(shù)據(jù)庫系統(tǒng)一般都是在應用中直接描述模式但是,用這種方式描述企業(yè)的數(shù)據(jù)需求,層次太低,不便用戶理解因此,需要一種更高層次的描述模式的方法,即數(shù)據(jù)模型現(xiàn)有的數(shù)據(jù)庫系統(tǒng)均是基于某種數(shù)據(jù)模型為什么需要數(shù)據(jù)模型?為了將數(shù)據(jù)的定義與操作從應用程序中分離出來,交由DBMS定義和管理,DBMS需要采用某種數(shù)據(jù)結構來定義、存儲所要管理的數(shù)據(jù)這種狹義的數(shù)據(jù)結構即相當于DBMS的數(shù)據(jù)模型數(shù)據(jù)抽象數(shù)據(jù)模型是數(shù)據(jù)庫技術的核心數(shù)據(jù)模型既提供了考慮面向數(shù)據(jù)處理應用的概念基礎,也提供了使用數(shù)據(jù)庫系統(tǒng)的技術和工具的形式基礎數(shù)據(jù)模型涉及數(shù)據(jù)的語法(syntactic)和語義(semantics)兩個方面而數(shù)據(jù)抽象則是數(shù)據(jù)模型的基礎數(shù)據(jù)抽象現(xiàn)實世界信息世界計算機世界概念化形式化用戶計算機信息世界數(shù)據(jù)庫系統(tǒng)是面向計算機的,而應用是面向現(xiàn)實世界的,兩個世界存在著很大差異要直接將現(xiàn)實世界中的語義映射到計算機世界是十分困難的因此需要引入一個信息世界作為現(xiàn)實世界通向計算機實現(xiàn)的“橋梁”信息世界一方面,信息世界是對現(xiàn)實世界的抽象,從紛繁的現(xiàn)實世界中抽取出能反映現(xiàn)實本質(zhì)的概念和基本關系另一方面,信息世界中的概念和關系,要以一定的方式映射到計算機世界中去,在計算機系統(tǒng)上最終實現(xiàn)信息世界起到承上啟下的作用數(shù)據(jù)模型的定義(1)數(shù)據(jù)模型是數(shù)據(jù)庫系統(tǒng)中用于提供信息表示和操作手段的形式構架應用概念數(shù)據(jù)模型結構數(shù)據(jù)模型現(xiàn)實世界信息世界計算機世界數(shù)據(jù)模型的定義(2)Adatamodelisanintegratedcollectionofconceptsfordescribingandmanipulatingdata,relationshipbetweendata,andconstraintsonthedatainanorganization數(shù)據(jù)模型的定義(3)Adatamodelrepresentationof“realworld”objectsandevents,andtheirassociationsIt’sabstractionthatconcentratesonessential,inherentaspectsofanorganizationandignorestheaccidentalproperties數(shù)據(jù)模型的定義(4)Adatamodelisacollectionofconceptsfordescribingdatapropertiesanddomainknowledge:DatarelationshipsDatasemanticsDataconstraints數(shù)據(jù)模型的定義(5)Adatamodelisanabstractmodelthatdescribeshowdataisrepresentedandaccessed數(shù)據(jù)模型的定義(5)Thetermdatamodelhastwogenerallyacceptedmeanings:Adatamodeltheory,i.e.aformaldescriptionofhowdatamaybestructuredandaccessedAdatamodelinstance,i.e.applyingadatamodeltheorytocreateapracticaldatamodelinstanceforsomeparticularapplication(datamodeling)

DatamodelingUnderstandingofdataFormaldefinitionsforrealworldthingsandrelationsbetweenthemUsinghighlevellanguagelikeUMLBasisofsoftwareengineeringStructuralrepresentationofdata:Relationaldatabases,XML…BasisforcommunicationbetweenITpeopleanddomainexperts對數(shù)據(jù)模型的要求(1)數(shù)據(jù)模型是對現(xiàn)實世界的表示,如何把現(xiàn)實世界的對象抽象為計算機可識別、可操作、并且是正確的數(shù)據(jù)集合,是數(shù)據(jù)模型的根本所在不同的數(shù)據(jù)模型提供了模型化數(shù)據(jù)和信息的不同工具對數(shù)據(jù)模型的要求(2)能比較真實地模擬現(xiàn)實世界容易為人所理解便于在計算機上實現(xiàn)注意:前2條與第3條之間往往是矛盾的!數(shù)據(jù)模型的組成要素結構部分:數(shù)據(jù)結構的集合,用于創(chuàng)建數(shù)據(jù)庫,表示由數(shù)據(jù)庫模擬的實體或?qū)ο蟛僮?manipulation)部分:運算子(operators)的集合,這些運算子可以被施用數(shù)據(jù)結構,更新和查詢數(shù)據(jù)庫內(nèi)的數(shù)據(jù)內(nèi)容完整性(integrity)約束部分:規(guī)則的集合,用于控制放置在這些數(shù)據(jù)結構上的約束以便保證結構的完整性數(shù)據(jù)結構數(shù)據(jù)結構定義了數(shù)據(jù)的組織規(guī)則,數(shù)據(jù)庫基于這些規(guī)則而構建,如關系模型中數(shù)據(jù)按域、屬性、關系等組織構建數(shù)據(jù)結構是刻畫一個數(shù)據(jù)模型性質(zhì)最重要的方面數(shù)據(jù)結構在數(shù)據(jù)庫系統(tǒng)中,人們通常按照其數(shù)據(jù)結構的類型來命名數(shù)據(jù)模型例如層次結構、網(wǎng)狀結構和關系結構的數(shù)據(jù)模型分別命名為層次模型、網(wǎng)狀模型和關系模型數(shù)據(jù)結構是對系統(tǒng)靜態(tài)特性的描述數(shù)據(jù)操作數(shù)據(jù)操作是指對數(shù)據(jù)庫中各種對象(型)的實例(值)允許執(zhí)行的操作的集合,包括操作及有關的操作規(guī)則數(shù)據(jù)庫主要有檢索和更新(包括插入、刪除、修改)兩大類操作數(shù)據(jù)操作是對系統(tǒng)動態(tài)特性的描述完整性約束數(shù)據(jù)的完整性約束是一組條件規(guī)則的集合完整性規(guī)則是給定的數(shù)據(jù)模型中數(shù)據(jù)及其聯(lián)系所具有的制約和依存規(guī)則,用以限定符合數(shù)據(jù)模型的數(shù)據(jù)庫狀態(tài)以及狀態(tài)的變化,以保證數(shù)據(jù)的正確、有效、相容例如,在學校的數(shù)據(jù)庫中規(guī)定大學生入學年齡不得超過30歲,碩士研究生入學年齡不得超過35歲,學生累計成績不得有三門以上不及格等等數(shù)據(jù)模型的分類根據(jù)模型描述的內(nèi)容和應用的層次不同,可劃分為:概念模型,也稱信息模型,它是按用戶的觀點來對數(shù)據(jù)和信息建模,主要用于數(shù)據(jù)庫設計數(shù)據(jù)模型,也稱邏輯模型,主要包括網(wǎng)狀模型、層次模型、關系模型、面向?qū)ο竽P偷?,它是按計算機系統(tǒng)的觀點對數(shù)據(jù)建模,主要用于DBMS的實現(xiàn)物理模型,也稱存儲模型,用于在最低層次上描述數(shù)據(jù),與具體實現(xiàn)有關數(shù)據(jù)模型的分類根據(jù)描述方法不同,可劃分為:基于記錄的邏輯模型:用記錄描述數(shù)據(jù),每個記錄由若干字段組成,與基于對象的邏輯模型不同,它不但描述了數(shù)據(jù)庫的全局邏輯結構,還提供關于實現(xiàn)的高層描述層次模型網(wǎng)狀模型關系模型基于對象的邏輯模型:用實體、屬性、聯(lián)系描述數(shù)據(jù),用于邏輯層和視圖層,包括實體-聯(lián)系模型(E-R)面向?qū)ο竽P?object-orientedmodel語義數(shù)據(jù)模型(Semanticmodel)數(shù)據(jù)模型的分類根據(jù)數(shù)據(jù)模型的表達方式,可劃分為:面向語法的vs.面向語義的Logicbasedvs.Graphbased根據(jù)數(shù)據(jù)模型的應用范圍,可劃分為:通用的vs.面向領域的……數(shù)據(jù)模型的分類根據(jù)數(shù)據(jù)模型的發(fā)展歷史,可劃分為:第一代:文件系統(tǒng)第二代:層次和網(wǎng)狀第三代:關系第四代:面向?qū)ο蠛涂蓴U展…:半(非)結構化、XML、RDF、Ontologe數(shù)據(jù)模型的分類(9/9)根據(jù)數(shù)據(jù)對象結構化程度,可劃分為:StructureddatamodelsSemi-structureddatamodelsUnstructureddatamodelsStructuredDataModels“Structured”dataDatahavearigidlyandpredefinedschema,thatcanberepresentedbyshortsymbolstringsandnumbersapplication-specificdatatypes:relations,objectsApplicationspecifictypesarecapturedinSchemasSchemasallowrepresentationofreal-worldconceptsastypes“real-worldsemantics”StructuredDataModels

Advantagesofschemasuseapplication-specificpredicatesandfunctionsforselectingdatamaintainintegrityofdataoptimizeaccesstoandstorageofdataStructuredDataModels

Eg,Relationaldatamodelcleanmathematicalfoundation:optimization,normalizationsimpletounderstandeachIDandNameisuniqueSchema:PGATour(ID,Name,Earning,DrivingDist)Unstructureddatamodels“Unstructured”DataAnydatawithoutawell-definedmodelforinformationaccess,suchasthenatural-languagetextofdocumentsorpictorialimagesExamples,WorddocumentsimagesUnstructuredDataManagement(UDM)TheprocessofminingandanalyzingunstructureddatatocaptureactionableinformationValueinUnstructuredData“Amountoftext-baseddataalonewillgrowtoover1600terabytesby2009”–Forrester2007“Amountofunstructureddatainlargecorporationsdoublesevery

18months”-IDC“Theaverageknowledgeworkerspends2.5hoursperdaysearchingfordocuments”-IDC–March2008“80-90%ofinformationonthecorporatenetworksisunstructured”-GoldmanSachsValueinUnstructuredDataBusinessValueBetterinformationMoretimelyinformationMorerelevantinformationBetterdecisionsupportITImpactMoreinformationtostoreandmanageMorecomplexanalysisGreaterbusinessimpactSource:METAGroup,9/20/2001UDMIncreasesInformationalContentStructuredData(10-40%)UnstructuredData(60-90%)+UDMComplementsStructuredDataUDMConsolidatedDataStructuredDataUnstructuredDataContextualInformationGreaterValueUDMTechnologiesText-MiningAudio-MiningImage-MiningDocumentsE-mailsWebpagesChatroomsNewsstoriesetc.TelephonecallsSpeechBroadcastsSoundsetc.PhotographsVideoTVbroadcastsArialphotogrammetrySurveillancecamerasetc.TextMiningTheprocessofextractinginformationfromtextualdata,andutilizingitforbetterbusinessdecisionsBasedonmultipletechnologies,e.g.,ComputationallinguisticsStatisticsAnewbusinessintelligencetoolFocuson“semantics”andnot“keywords”AnemergingtechnologyComputationalLinguisticsDefinitionStudyofcomputeralgorithmsfor:NaturallanguageunderstandingNaturallanguagegenerationObjectivesMachinetranslationInformationretrievalHuman-MachineinterfaceEarlyworkbeganin1950sSyntaxAnalysisStructureDetermination:GenerationofaparsetreeusingagrammarSentenceSubjectVerbPhraseVerbObjectMaryeatscheeseSemanticAnalysisExampleofambiguitiesatthesyntacticlevel:“Isawamanintheparkwithatelescope”SemanticanalysisisrequiredSynonymsDeepparsingPriorknowledgeCategoriesofText-MiningFeatureExtractionEntities(e.g.,names,companies,places)Events(e.g.,mergers,elections,sales)RelationsamongentitiesandeventsDocumentCategorizationGroupingmultiplearticlesbasedontheircontextualsimilaritiesCategoriesofText-MiningSummarization(摘要)Acondensed(濃縮的)versionofoneormoredocumentsDocumentNavigation(導航)Thematic(主題)AnalysisDiscoveryofthetheme/contextwithinadocumentSampleApplicationsNewsanalysisforevidencegatheringPatentanalysisE-mailroutingCompetitiveintelligenceWarrantyclaimsanalysisCRMContentmanagementMarketresearchRecruitingHumanResourceeLearningAutomatedhelp-desksChatroommonitoringWebpagemonitoringDocumentclusteringLegacydocumentconversionMachinetranslationKnowledgemanagementIntelligentsearchenginese-ProcurementAudioMiningAnalysisofaudiodataSpeechMusicOthersoundsGoal:ExtractinformationfromaudioWhoisthespeakerWhatissaidDefectdetectionMusicidentificationTelecommunicationsmonitoringAudioMiningAnalysisisbasedonaudioattributes,e.g.,Volume(音量)Pitch(音調(diào))Timber(音質(zhì))SourcesofaudioforanalysisVoicerecordingsFactorysoundsTelecommunicationsBroadcastsetc.SampleApplicationsBroadcastcontentmanagementCallcenterautomationCRMManufacturingqualitycontrolMusicretrieval(querybyhumming)etc.ImageMiningAnalysisofdigitalimagesPicturesDrawingsVideosGoal:ExtractinformationfromimagesFacerecognitionDefectdetectionObjectrecognitionAction/eventdetectionImageMiningAnalysisisbasedonspatialattributese.g.,ColorSizeTexture(macroandmicro)紋理ShapesOutlinesShadowsSourcesofimagesDigitalphotographsSurveillance監(jiān)視camerasBroadcastsetc.SampleApplicationsManufacturingqualitycontrolBroadcastcontentmanagementRemoteSensingSecurityandauthenticationVideologsGeophysics地球物理AerialPhotogrammetry航空攝影學RelatedTechnologiesBusinessIntelligenceKnowledgeManagementContentManagementE-LearningInnovationManagementSalesForceAutomationDataMiningDataVisualizationSampleArchitectureInformationExtractionRulesDataWarehouseStructuredDataAnalysisandDecisionSupportUnstructuredDataVisualizationSemi-StructuredDataDatadoesnothavearigidlyandpredefinedschema,butdatahasacertaindegreeofschemas,whichmakesitunderstandableandusefule.g.,HTML,XML,scientificdata,…Semi-StructuredDataManagingsuchdatarequiresrethinkingthedesignofcomponentsofaDBMS:datamodelquerylanguageoptimizerstoragesystem…Semi-StructuredDataExampleofSemi-StructuredData:name:PeterWoodemail:ptw@dcs.bbk.ac.uk,p.wood@bbk.ac.ukname:firstname:Marklastname:Leveneemail:mark@dcs.bbk.ac.ukname:AlexPoulovassilisaffiliation:BirkbeckSemi-StructuredDataModelsImportantaspectsforsemi-structureddatamodelsrepresentationofrelationships:hypertextgraphs,semanticnetworksself-describing:schema-lessdataVolatility(易變性):changingschemasstandardization:representdatafromanystructuredmodelserializability:exchangeofdocumentsSemi-StructuredDataModelsThesemi-structuredmodelisadatabasemodelInthismodel,thereisnoseparationbetweenthedataandtheschema,andtheamountofstructureuseddependsonthepurposeSemi-StructuredDataModelsGraphs-basedortrees-basedtypicaloperation:navigationLogic-basedtypicaloperation:inference2.2經(jīng)典數(shù)據(jù)模型回顧層次(Hierarchical)模型(略講)網(wǎng)狀(Network)模型(略講)關系(Relational)實體-聯(lián)系(EntityRelationship)層次模型(略講)

按照層次結構(即樹型結構)來組織數(shù)據(jù),樹中的每一個結點表示一個記錄類型,箭頭表示雙親-子女關系

性質(zhì)有且僅有一個結點無雙親,該結點稱為根結點其它結點有且僅有一個雙親,這些結點稱為從屬結點由“雙親子女關系”確定記錄間的聯(lián)系,上一層記錄類型和下一層記錄類型的聯(lián)系是一對多聯(lián)系

特點反映現(xiàn)實世界中數(shù)據(jù)的層次關系,比較簡單、直觀。

通過指針來實現(xiàn)記錄之間的聯(lián)系,查詢效率較高。

只能描述1:M聯(lián)系,且復雜的層次使得數(shù)據(jù)的查詢和更新操作比較復雜。

網(wǎng)狀模型(略講)

使用有向圖(網(wǎng)絡)結構表示實體類型和實體間類型的數(shù)據(jù)模型,又稱為網(wǎng)絡模型。

結點具有的性質(zhì):

至少有一個結點有多于一個雙親結點

可以有一個以上的結點無雙親結點

特點:

能夠描述M:N聯(lián)系。

通過指針來實現(xiàn)記錄之間的聯(lián)系,查詢效率較高

編寫應用程序比較復雜關系模型(回顧)數(shù)據(jù)結構關系模型的完整性關系運算關系代數(shù)關系演算關系數(shù)據(jù)庫語言SQL關系數(shù)據(jù)庫理論關系模型擴展關系模型數(shù)據(jù)結構直觀描述用二維表來表示實體及其相互聯(lián)系屬性元組男女男性別192221年齡D01李紅S02D02王偉S03D01張軍S01系號姓名學號關系模型數(shù)據(jù)結構數(shù)學定義域:原子值的集合元組:(d1,…,dn)笛卡爾積:D1×…×Dn關系:元組集合關系模式:R(A1,…,An)鍵:超鍵、候選鍵、主鍵、外鍵關系模型的完整性域完整性實體完整性參照完整性用戶定義完整性關系運算關系代數(shù)以集合代數(shù)為基礎,以“關系”為運算對象和結果的代數(shù)演算系統(tǒng)代數(shù)演算系統(tǒng)的組成運算對象+運算符+封閉性+運算規(guī)則關系演算以謂詞演算為基礎,以元組(域)變量為謂詞變元的邏輯演算系統(tǒng)課后復習

Chapter3:RelationalModel(第4版)關系數(shù)據(jù)庫的結構StructureofRelationalDatabases關系代數(shù)RelationalAlgebra元組關系演算TupleRelationalCalculus域關系演算DomainRelationalCalculus擴展關系代數(shù)操作ExtendedRelational-Algebra-Operations數(shù)據(jù)庫更新ModificationoftheDatabase視圖Views關系數(shù)據(jù)庫語言SQL數(shù)據(jù)定義語言(DDL)數(shù)據(jù)查詢語言(QL)基本查詢塊集合運算嵌套(子)查詢數(shù)據(jù)操縱語言(DML)數(shù)據(jù)控制語言(DCL)嵌入式SQLSQLAPICLI/ODBC/JDBC課后復習

Chapter4:SQL(第4版)基本結構BasicStructure集合操作SetOperations聚集函數(shù)AggregateFunctions空值NullValues嵌套子查詢NestedSubqueries派生關系DerivedRelations視圖Views數(shù)據(jù)庫更新ModificationoftheDatabase連接關系JoinedRelations數(shù)據(jù)定義語言DataDefinitionLanguage嵌入式SQL,ODBC和JDBC。EmbeddedSQL,ODBCandJDBC關系數(shù)據(jù)庫理論關系數(shù)據(jù)庫設計的理論基礎數(shù)據(jù)依賴函數(shù)依賴(FD)、多值依賴(MVD)、連接依賴(JD)邏輯蘊含(|=)、邏輯導出(=>)、Armstrong公理、FD集合閉包屬性集合閉包、FD集合的等價覆蓋、最小FD集合關系數(shù)據(jù)庫理論關系模式分解無損連接分解、保持FD分解、判別算法關系模式規(guī)范化1NF2NF3NFBCNF4NF5NF規(guī)范化算法(分解法、合成法)課后復習

Chapter7:RelationalDatabaseDesign(第4版)FirstNormalFormPitfalls(陷阱)inRelationalDatabaseDesignFunctionalDependenciesDecompositionBoyce-CoddNormalFormThirdNormalFormMultivaluedDependenciesandFourthNormalFormOverallDatabaseDesignProcess關系模型擴展嵌套(非1NF)關系模型可擴展的對象-關系模型時態(tài)關系模型概率關系模型模糊關系模型E-R模型(回顧)

E-R模型是實體-聯(lián)系(Entity-Relationship)模型的縮寫,是一種概念數(shù)據(jù)模型

基本思想:首先設計一個概念模型,它是現(xiàn)實世界中實體及其聯(lián)系的一種信息結構,不依賴于具體的計算機系統(tǒng),與存儲組織、存取方法、效率等無關然后再將概念模型轉(zhuǎn)換為計算機上某個數(shù)據(jù)庫管理系統(tǒng)所支持的邏輯數(shù)據(jù)模型在E-R模型中包括:實體、聯(lián)系和屬性三種基本成分

E-R模型

實體(Entity):即實在之體,是可區(qū)別且可被識別的客觀存在的事、物或概念。具有共性的實體可劃分為實體集。實體的內(nèi)涵用實體類型表示屬性(Attribute):是實體所具有的特性或特征。一個實體可以有多個屬性。不能再細分的屬性稱為原子屬性,還可以細分的屬性稱為可分屬性。屬性的可能取值范圍稱為屬性的值域,簡稱為屬性域。屬性將實體集中每個實體和該屬性的值域中的一個值聯(lián)系起來。一個實體諸屬性的一組特定的屬性值,確定一個特定的實體E-R模型

實體(Entity)定義:即實在之體,是客觀存在的且可被識別的事、物或概念實體集(EntitySet):具有共性的實體可劃分為實體集實體類型(EntityType):實體的內(nèi)涵用實體類型表示要點:①客觀存在②可以標識E-R模型

屬性(Attribute)定義:實體及聯(lián)系所具有的特性或特征,一個實體可以有多個屬性。原子屬性與可分屬性:不能再細分的屬性稱為原子屬性,可以細分的屬性稱為可分屬性單值屬性與多值屬性:只能取單個值的屬性稱為單值屬性,可以取多個值的屬性稱為多值屬性值域:屬性的取值范圍稱為屬性的值域,簡稱為屬性域值標識:屬性將實體集中每個實體和該屬性的值域中的一個值聯(lián)系起來,一個實體諸屬性的一組特定的屬性值,可唯一標識一個特定的實體E-R模型

聯(lián)系(relationship)定義:發(fā)生在實體之間具有特定含義的對應關系聯(lián)系值與聯(lián)系集:二元聯(lián)系與多元聯(lián)系:角色(role):基數(shù)比約束(cardinalityratioconstraint):

二元聯(lián)系:1:1,1:M,M:N

三元聯(lián)系:1:1:1,1:1:P,1:N:P,M:N:P實體的參與度:(min,max),0<=min<=max>=1部分參與(min=0)和全參與(min>0):聯(lián)系的屬性:強實體與弱實體:E-R圖

E-R圖的基本符號

矩形框:表示實體類型

菱形框:表示聯(lián)系類型

橢圓形框:表示實體類型和類型類型的屬性

直線:聯(lián)系類型與其相關的實體類型之間用直線相連接,并在其旁邊標記聯(lián)系的種類(1:1、1:N或M:N),表示實體與聯(lián)系之間的關系E-R圖的設計步驟確定實體類型

確定聯(lián)系類型

確定實體類型和聯(lián)系類型的屬性

畫出E-R圖E-R模型中使用的符號匯總E-R模型中使用的符號匯總課后復習

Chapter2:Entity-RelationshipModel(第4版)EntitySets實體集RelationshipSets聯(lián)系集DesignIssues模型設計MappingConstraints 映射約束Keys碼E-RDiagramE-R圖ExtendedE-RFeatures擴展E-R功能DesignofanE-RDatabaseSchemaE-R數(shù)據(jù)庫模式的設計ReductionofanE-RSchematoTablesE-R模式轉(zhuǎn)換成表經(jīng)典數(shù)據(jù)模型的不足經(jīng)典數(shù)據(jù)模型都是基于記錄,面向機器的經(jīng)典數(shù)據(jù)模型缺乏對以下特征的支持DataabstractionComplexConstraintsUnstructuredobjectsDynamicpropertiesofanapplication子類關系(has-subtype)屬性關系(has-attribute)實例關系(has-instance)2.3Object-OrientedDataModel

(9/14)Describesasystemusingclasses,operations,classcooperationandbehaviourExtensionoftheEntity-RelationshipmodelClass=EntityCanmodeldifferentaspectsofdata/entitiesGeneralisationhierarchyCompositedatatypes/AggregationObjectbehaviour/Operations(methods)CanmodeldifferentaspectofthesystemDomainmodel/DesignmodelInteractionbetweenobjects(user/system/classes)ObjectOrientedCoreConceptsTheobject-orientedparadigmisbasedonencapsulatingcodeanddatarelatedtoanobjectintosingleunit--objectAdaptationoftheobject-orientedprogrammingparadigm(e.g.,Smalltalk,C++)todatabasesystemsObjectOrientedCoreConceptsObjectPropertiesofobjectsObjectIdentity(OID)

MethodsEncapsulationLiteralClassification&TaxonomyClassesInheritancePolymorphism

Overloading,overriding,andlatebindingCoreConceptsObjectStructureAnobjecthasassociatedwithit:Asetofvariablesthatcontainthedatafortheobject.Thevalueofeachvariableisitselfanobject.Asetofmessagestowhichtheobjectresponds;eachmessagemayhavezero,one,ormoreparameters.Asetofmethods,eachofwhichisabodyofcodetoimplementamessageamethodreturnsavalueastheresponsetothemessageThephysicalrepresentationofdataisvisibleonlytotheimplementoroftheobjectMessagesandresponsesprovidetheonlyexternalinterfacetoanobjectMessagesandMethodsThetermmessagedoesnotnecessarilyimplyphysicalmessagepassingMessagescanbeimplementedasprocedureinvocationsMethodsareprogramswritteningeneral-purposelanguagewiththefollowingfeaturesonlyvariablesintheobjectitselfmaybereferenceddirectlydatainotherobjectsarereferencedonlybysendingmessagesMessagesandMethodsStrictlyspeaking,everyattributeofanentitymustberepresentedbyavariableandtwomethods,e.g.,theattributeaddressisrepresentedbyavariableaddressandtwomessagesget-addressandset-addressForconvenience,manyobject-orienteddatamodelspermitdirectaccesstovariablesofotherobjectsObjectClassesSimilarobjectsaregroupedintoaclass;eachsuchobjectiscalledaninstanceofitsclassAllobjectsinaclasshavethesamevariabletypesmessageinterfaceMethodsThemaydifferinthevaluesassignedtovariablesClassesareanalogoustoentitysetsintheE-RmodelClassDefinitionExampleclassemployee{

/*Variables*/

string name;

string address;

date

start-date;

int salary;

/*Messages*/

int annual-salary();

string get-name();

string get-address();

int set-address(stringnew-address);

int employment-length();

};Forstrictencapsulation,methodstoreadthesetothervariablesarealsoneededInheritanceE.g.,classofbankcustomerssimilartoclassofbankemployees:bothsharesomevariablesandmessages,e.g.,nameandaddressButtherearevariablesandmessagesspecifictoeachclasse.g.,salaryforemployeesandcredit-ratingforcustomers.Everyemployeeisaperson;thusemployeeisaspecializationofpersonInheritanceEveryemployeeisaperson;thusemployeeisaspecializationofpersonSimilarly,customerisaspecializationofpersonCreateclassesperson,employeeandcustomervariables/messagesapplicabletoallpersonsassociatedwithclassperson.variables/messagesspecifictoemployeesassociatedwithclassemployeesimilarlyforcustomerInheritancePlaceclassesintoaspecialization/IS-Ahierarchyvariables/messagesbelongingtoclasspersonareinheritedbyclassemployeeaswellascustomerResultisaclasshierarchyClassHierarchyExample

classperson{

string name;

string address:

};

classcustomerisaperson{

intcredit-rating;

};

classemployeeisaperson{

datestart-date;

intsalary;

};

classofficerisaemployee{

intoffice-number,

intexpense-account-number,

};

...ClassHierarchyExampleFullvariablelistforobjectsintheclassofficer:office-number,expense-account-number:definedlocallystart-date,salary:inheritedfromemployeename,address:inheritedfrompersonMethodsinheritedsimilartovariablesSubstitutabilityAnymethodofaclass,sayperson,canbeinvokedequallywellwithanyobjectbelongingtoanysubclass,suchassubclassofficerofpersonClassextentClassextent(類外延/區(qū)間):setofallobjectsintheclass.Twooptions:1. Classextentofemployeeincludesallofficer,tellerandsecretaryobjects.2. Classextentofemployeeincludesonlyemployeeobjectsthatarenotinasubclasssuchasofficer,teller,orsecretaryMultipleInheritanceTheclass/subclassrelationshipisrepresentedbyadirectedacyclicgraph(DAG)aclassmayhavemorethanonesuperclass.AclassinheritsvariablesandmethodsfromallitssuperclassesThereispotentialforambiguity.E.g.,variablewiththesamenameinheritedfromtwosuperclassesDifferentsolutionssuchasflaganderror,renamevariables,orchooseoneMultipleInheritanceCanusemultipleinheritancetomodel“roles”ofanobject.Apersoncanplaytherolesofstudent,ateacherorfootballPlayer,oranycombinationofthethreee.g.,studentteachingassistantwhoalsoplayfootballCreatesubclassessuchasstudent-teacherandstudent-teacher-footballPlayerthatinheritfrommultipleclassesExampleofMultipleInheritanceClassDAGforbankingexample.ObjectIdentifiersObjectidentifiersusedtouniquelyidentifyobjectsCanbestoredasafieldofanobject,torefertoanotherobject.E.g.,thespousefieldofapersonobjectmaybeanidentifierofanotherpersonobjectCanbesystemgenerated(createdbydatabase)orexternal(suchassocial-securitynumber)ObjectIdentityAnobjectretainsitsidentityevenifsomeorallofthevaluesofvariablesordefinitionsofmethodschangeovertimeObjectidentityisastrongernotionofidentitythaninprogramminglanguagesordatamodelsnotbasedonobjectorientationValue–datavalue;usedinrelationalsystemsName–suppliedbyuser;usedforvariablesinprocedures.Built-in–identitybuiltintodatamodelorprogramminglanguage.nouser-suppliedidentifierisrequired.formofidentityusedinobject-orientedsystems.ObjectContainmentEachcomponentinadesignmaycontainothercomponentsCanbemodeledascontainmentofobjects.Objectscontaining;otherobjectsarecalledcompositeobjects.Multiplelevelsofcontainmentcreateacontainmenthierarchy:linksinterpretedasis-part-of,notis-a.Allowsdatatobeviewedatdifferentgranularitiesbydifferentusers.Object-OrientedLanguagesObject-orientedconceptscanbeusedasadesigntool,andbeencodedinto,forexample,arelationaldatabaseTheconceptsofobjectorientationcanbeincorporatedintoaprogramminglanguagethatisusedtomanipulatethedatabasePersistentprogramminglanguages

Extendobject-orientedprogramminglanguagetodealwithdatabasesbyaddingconceptssuchaspersistenceandcollectionsPersistentProgrammingLanguagesAllowobjectstobecreatedandstoredinadatabasewithoutanyexplicitformatchanges(formalchangesarecarriedouttransparently).Allowobjectstobemanipulatedin-memory–donotneedtoexplicitlyloadfromorstoretothedatabaseAllowdatatobemanipulateddirectlyfromtheprogramminglanguagewithouthavingtogothroughadatamanipulationlanguagelikeSQLPersistentProgrammingLanguagesDuetopowerofmostprogramminglanguages,itiseasytomakeprogrammingerrorsthatdamagethedatabaseComplexityoflanguagesmakesautomatichigh-leveloptimizationmoredifficultDonotsupportdeclarativequeryingverywell.PersistenceofObjectsApproachestomaketransientobjectspersistentincludeestablishingpersistenceby:Class–declareallobjectsofaclasstobepersistent;simplebutinflexible.Creations–extendthesyntaxforcreatingtransientobjectstocreatepersistentobjects.Marking–anobjectthatistopersistbeyondprogramexecutionismarkedaspersistentbeforeprogramtermination.Reference-declare(root)persistentobjects;objectsarepersistentiftheyarereferredto(directlyorindirectly)fromarootobject.ObjectIdentityandPointersAPersistentobjectisassignedapersistentobjectidentifier.Degreesofpermanenceofidentity:Intraprocedure–identitypersistsonlyduringtheexecutionsofasingleprocedureIntraprogram–identitypersistsonlyduringexecutionofasingleprogramorquery.Interprogram–identitypersistsfromoneprogramexecutiontoanother.Persistent–identitypersiststhroughoutprogramexecutionsandstructuralreorganizationsofdata;requiredforobject-orientedsystems.ObjectIdentityandPointersInO-OlanguagessuchasC++,andobjectidentifierisactuallyanin-memorypointerPersistentpointer:persistsbeyondprogramexecution,canbethoughtofasapointerintothedatabaseStorageandAccessof

PersistentObjectsNameobjects(asyouwouldnamefiles)–cannotscaletolargenumberofobjectstypicallygivenonlytoclassextentsandothercollectionsofobjects,butnotobjects.Exposeobjectidentifiersorpersistentpointerstotheobjects–canbestoredexternally.AllobjectshaveobjectidentifiersStorecollectionsofobjectsandallowprogramstoiterateoverthecollectionstofindrequiredobjectsModelcollectionsofobjectsascollectiontypesClassextent-thecollectionofallobjectsbelongingtotheclass;usuallymaintainedforallclassesthatcanhavepersistentobjectsHowtofindobjectsinthedatabase:PersistentC++SystemsC++languageallowssupportforpersistencetobeaddedwithoutchangingthelanguageDeclareaclasscalledPersistent_ObjectwithattributesandmethodstosupportpersistenceOverloadingabilitytoredefinestandardfunctionnamesandoperators(i.e.,+,–,thepointerdeferenceoperator–)whenappliedtonewtypesPersistentC++SystemsProvidingpersistencewithoutextendingtheC++languageisrelativelyeasytoimplementbutmoredifficulttouseODMGC++ObjectDefinitionLanguageStandardizelanguageextensionstoC++tosupportpersistenceODMGusesstandardC++,providingmostfunctionalityviatemplateclassesandclasslibrariesTemplateclassd_Ref<class>usedtospecifyreferences(persistentpointers)Templateclassd_Set<class>usedtodefinesetsofobjects.Providesmethodssuchasinsert_elementanddelete_elementODMGC++ObjectDefinitionLanguageOthercollectionclassessuchasd_Bag(setwithduplicatesallowed),d_Listandd_Varray(variablelengtharray)alsoprovided.d_versionofmanystandardtypesprovided,e.g.d_Long.Interpretationofthesetypesisplatformindependent.ODMGC++ODL:ExampleclassPerson:publicd_Object{

public:

d_Stringname;//shouldnotuseString! d_Stringaddress;

};classCustomer:publicPerson{

public:

d_Datemember_from;

d_Longcustomer_id;

d_Ref<Branch>home_branch;

d_Set<Ref<Account>>accounts;};ODMGC++ODL:ExampleclassAccount:publicd_Object{

private:

d_Longbalance;

public:

d_Longnumber;

d_Set<d_Ref<Customer>>owners intfind_balance();

intupdate_balance(intdelta);

};ImplementingRelationshipsRelationshipsbetweenclassesimplementedbyreferences;specialreferencetypesenforcesintegritybyadding/removinginverselinks.Typed.Rel.Ref<Class,InvRef>isareferencetoClass,whereattributeInvRefOfClass,istheinversereference.Similarly,d.Rel.Set<Class,InvRef>forasetofreferences

ImplementingRelationships

externconstchar_owners[],_accounts[];

classAccount:publicd.Object{

….

d.Rel.Set<Customer,_accounts>owners;

}

//Sincestringscan’tbeusedintemplates…

constchar_owners=“owners”;

constchar_accounts=“accounts’;ODMGObjectModelODMG(ObjectDataManagementGroup)EstablishedbyvendorsofOODBMSstodefinestandardsHaveproducedanObjectModelthatspecifiesastandardmodelforthesemanticsofdatabaseobjectsDesignofclasslibrariesandapplicationsusingthesesemanticsshouldbeportableacrossvariousOODBMSsODMGObjectModelMajorcomponentsofODMGarchitectureforanOODBMSare:ObjectModel(OM)ObjectDefinitionLanguage(ODL)ObjectQueryLanguage(OQL)LanguageBinding:C++,Smalltalk,JavaODMGOM–

BasicModelingPrimitivesBasicmodelingpr

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論