




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第16講
基于對(duì)象的數(shù)據(jù)庫(kù)
重慶大學(xué)計(jì)算機(jī)學(xué)院課程名稱(chēng):數(shù)據(jù)庫(kù)系統(tǒng)
--------------------對(duì)象關(guān)系模型ORDBMExtendtherelationaldatamodelbyincluding
objectorientation面向?qū)ο?/p>
andconstructstodealwithaddeddatatypes.Allowattributesoftuplestohavecomplextypes,includingnon-atomicvaluessuchasnestedrelations.Preserverelationalfoundations,inparticularthedeclarativeaccesstodata,whileextendingmodelingpower.Upwardcompatibility
向上兼容
withexistingrelationallanguages.對(duì)象關(guān)系數(shù)據(jù)庫(kù)管理系統(tǒng)ORDBMS基于對(duì)象關(guān)系數(shù)據(jù)模型的數(shù)據(jù)庫(kù)管理系統(tǒng)1.1對(duì)象關(guān)系數(shù)據(jù)模型Object-RelationalDataModels一對(duì)象關(guān)系數(shù)據(jù)庫(kù)基本概念關(guān)系模型設(shè)計(jì)面臨障礙:關(guān)系模型僅支持非常有限的數(shù)據(jù)類(lèi)型,難以描述許多客觀存在的復(fù)雜結(jié)構(gòu)(記錄結(jié)構(gòu),多值屬性,繼承)這些復(fù)雜結(jié)構(gòu)E-R模型本身是能很好的支持的,但在形成相應(yīng)關(guān)系模式結(jié)構(gòu)時(shí)被強(qiáng)制轉(zhuǎn)換為簡(jiǎn)單的SQL數(shù)據(jù)類(lèi)型將傳統(tǒng)關(guān)系模型擴(kuò)展到對(duì)象關(guān)系模型是為了想要使用面向?qū)ο筇卣鞯年P(guān)系數(shù)據(jù)庫(kù)用戶提供一個(gè)移植途徑,以更好地滿足應(yīng)用的實(shí)際需要SQL標(biāo)準(zhǔn)SQL1999版本(以及SQL2003),特別增加了對(duì)象關(guān)系擴(kuò)展描述部分注意,大多數(shù)數(shù)據(jù)庫(kù)產(chǎn)品都只支持SQL標(biāo)準(zhǔn)的一個(gè)子集,需要實(shí)際查閱相關(guān)的用戶手冊(cè)對(duì)象關(guān)系數(shù)據(jù)模型的用途動(dòng)機(jī)Motivation:Permitnon-atomicdomains(indivisible不可分的)Exampleofnon-atomicdomain:setofintegers,orsetoftuplesAllowsmoreintuitivemodelingforapplicationswithcomplexdata直觀說(shuō)明Intuitivedefinition:allowrelationswheneverweallowatomic(scalar)values, 比如:relationswithinrelationsRetains保留mathematicalfoundationofrelationalmodelViolates
違反firstnormalform.例子:關(guān)系看著屬性值傳統(tǒng)處理方式:表示數(shù)據(jù)對(duì)象傳統(tǒng)方式存在的不足:不足分析復(fù)雜數(shù)據(jù)類(lèi)型1.2復(fù)雜數(shù)據(jù)類(lèi)型Example:libraryinformationsystem(圖書(shū)館信息系統(tǒng))Eachbookhastitle,asetofauthors,Publisher,andasetofkeywordsNon-1NFrelation
books:ExampleofaNestedRelation結(jié)構(gòu):內(nèi)容:多值屬性記錄結(jié)構(gòu)屬性多值屬性Removeawkwardness笨拙offlat-books
扁平關(guān)系byassumingthatthefollowingmultivalueddependencieshold:titleauthortitle
keywordtitle
pub-name,pub-branchDecompose
flat-doc扁平文檔內(nèi)容into4NFusingtheschemas: (由4NF分解算法)authors(title,author)keywords(title,keyword)book4(title,pub-name,pub-branch)4NFDecompositionofNestedRelation1.2復(fù)雜數(shù)據(jù)類(lèi)型4NFDecompositionofflat–books傳統(tǒng)方式表示的不足4NFdesignrequiresuserstoincludejoinsintheirqueries.1NFrelationalviewflat-books
definedbyjoinof4NFrelations:eliminatestheneedforuserstoperformjoins,butlosestheone-to-onecorrespondencebetweentuplesanddocuments.Andhasalargeamountofredundancy新方式表示的優(yōu)點(diǎn)Nestedrelationsrepresentationismuchmorenaturalhere.Problemswith4NFSchemaExtensionstoSQLtosupportcomplextypesinclude:CollectionandlargeobjecttypesNestedrelationsareanexampleofcollectiontypesStructuredtypesNestedrecordstructureslikecompositeattributesInheritanceObjectorientationIncludingobjectidentifiersandreferencesOurdescriptionismainlybasedontheSQL:1999standardNotfullyimplementedinanydatabasesystemcurrentlyButsomefeaturesarepresentineachofthemajorcommercialdatabasesystemsReadthemanualofyourdatabasesystemtoseewhatitsupportsComplexTypesinSQL:1999二SQL支持的復(fù)雜數(shù)據(jù)類(lèi)型創(chuàng)建:StructuredtypescanbedeclaredandusedinSQL createtypeNameas
(firstname
varchar(20),
lastnamevarchar(20))
final
createtypeAddressas
(streetvarchar(20),
city varchar(20),
zipcode varchar(20))
notfinal
Note:
final
and
notfinal
indicatewhethersubtypescanbecreated (如:final---不允許在該類(lèi)型下創(chuàng)建子類(lèi),見(jiàn)后9.3.2節(jié),p.242)使用:Structuredtypescanbeusedtocreatetableswithcompositeattributescreatetablecustomer(
name Name, address Address, dateOfBirth
date)說(shuō)明:Dotnotationusedtoreferencecomponentsofstructuredatrubites:name.firstnameStructuredTypes-可作屬性使用2.1SQL-結(jié)構(gòu)類(lèi)型創(chuàng)建:User-definedrowtypes(可以利用已定義結(jié)構(gòu)定義新的結(jié)構(gòu))createtype
CustomerType
as(
nameName, addressAddress, dateOfBirth
date)
notfinal使用:Canthencreateatablewhoserowsareauser-definedtypecreatetable
customer
of
CustomerTypeStructuredTypes-可作表使用2.1SQL-結(jié)構(gòu)類(lèi)型結(jié)構(gòu)定義時(shí)可申明方法:Canaddamethoddeclarationwithastructuredtype.
method
ageOnDate(onDate
date)
returnsintervalyear方法體需要單獨(dú)編寫(xiě):Methodbodyisgivenseparately.create
instancemethod
ageOnDate(onDate
date)
returnsintervalyear for
CustomerTypebegin return
onDate-self.dateOfBirth;當(dāng)前日期減去出生日期end注:SELFreferstothistuple
instance指出該方法在CustomerType的實(shí)例上執(zhí)行方法的使用方式:Wecannowfindtheageofeachcustomer:select
name.lastname,ageOnDate(current_date)from
customer注:Dot是系統(tǒng)提供的缺省方法!補(bǔ)充:另一例子如何提取復(fù)雜結(jié)構(gòu)里的數(shù)據(jù)2.1SQL-結(jié)構(gòu)類(lèi)型
.P.451(example9.21:EndtoMethod….)Separately,weneedtodefinethemethodhouseNumber()astheform: CREATEMETHODhouseNumber()RETURNSCHAR(10) FORAddressType BEGIN
…… END;AnotherExampleofmethods
參考:《數(shù)據(jù)庫(kù)系統(tǒng)基礎(chǔ)教程》(中譯本),斯坦福大學(xué),機(jī)械工業(yè)出版社出版,2009.08,1版declarationdefinition10.1510.172.1SQL-結(jié)構(gòu)類(lèi)型子類(lèi)繼承:Supposethatwehavethefollowingtypedefinitionforpeople:
createtype
Person
(namevarchar(20),
addressvarchar(20)) Using
inheritancetodefinethestudentandteachertypes
createtype
Student
underPerson
(degreevarchar(20),
departmentvarchar(20))
createtypeTeacher
underPerson
(salaryinteger,
departmentvarchar(20))多態(tài)性:SubtypescanredefinemethodsbyusingoverridingmethodinplaceofmethodinthemethoddeclarationInheritance2.2SQL-繼承類(lèi)型不支持:SQL:1999andSQL:2003donotsupportmultipleinheritance假想的類(lèi)型繼承:Ifourtypesystemsupportsmultipleinheritance,wecandefineatypeforteachingassistantasfollows:
createtypeTeachingAssistant
underStudent,TeacherToavoidaconflictbetweenthetwooccurrencesofdepartmentwecanrenamethemcreatetypeTeachingAssistant
under
Studentwith(departmentasstudent_dept),分情況選擇繼承
Teacherwith(departmentasteacher_dept
)*MultipleInheritance
-同時(shí)為多個(gè)類(lèi)型的子類(lèi)2.2SQL-繼承類(lèi)型Student類(lèi)型的屬性名說(shuō)明:數(shù)組-在SQL1999增加,多重集合-在SQL2003增加定義方式:Exampleofarrayandmultisetdeclaration: createtypePublisheras結(jié)構(gòu)類(lèi)型
(name
varchar(20),
branchvarchar(20))
createtypeBookas
(titlevarchar(20),
author-arrayvarchar(20)array[10],
數(shù)組-可存10個(gè)姓名,每個(gè)20字符
pub-datedate,
publisherPublisher,
keyword-setvarchar(20)multiset
)
可存多個(gè)關(guān)鍵字,每個(gè)20子符
createtablebooksof
Book該關(guān)系模式允許存儲(chǔ)的實(shí)例就是本課開(kāi)始時(shí)希望的復(fù)雜數(shù)據(jù)對(duì)象ArrayTypes&MultisetTypes2.3SQL-數(shù)組和多重集合類(lèi)型數(shù)組構(gòu)造器Arrayconstruction:array[‘Silberschatz’,`Korth’,`Sudarshan’]多重集合構(gòu)造器Multisetsconstruction: multisetset[‘computer’,‘database’,‘SQL’]產(chǎn)生復(fù)雜結(jié)構(gòu)元組值Tocreateatupleofthetypedefinedbythebooksrelation: (‘Compilers’,array[`Smith’,`Jones’],
new
Publisher(`McGraw-Hill’,`NewYork’), multiset[`parsing’,`analysis’])
注:new是指調(diào)用Publisher構(gòu)造函數(shù)(和調(diào)用參數(shù))為Publisher屬性創(chuàng)建一個(gè)值,Publisher構(gòu)造函數(shù)可用createfunction定義,如p.242的name構(gòu)造函數(shù)定義。插入復(fù)雜結(jié)構(gòu)元組到表中Toinserttheprecedingtupleintotherelationbooks:insertinto
books
values
(‘Compilers’,array[`Smith’,`Jones’],
new
Publisher(`McGraw-Hill’,`NewYork’),
.multiset[`parsing’,`analysis’])CreationofCollectionValues(inSQL1999)2.3SQL-數(shù)組和多重集合類(lèi)型Tofindallbooksthathavetheword“database”asakeyword, selecttitle
frombooks
where‘database’in(unnest(keyword-set))WecanaccessindividualelementsofanarraybyusingindicesE.g.:Ifweknowthataparticularbookhasthreeauthors,wecouldwrite: selectauthor-array[1],author-array[2],author-array[3]
frombooks
wheretitle=`DatabaseSystemConcepts’Togetarelationcontainingpairsoftheform“title,author-name”foreachbookandeachauthorofthebookselectB.title,A.author
frombooksasB,unnest(B.author-array)asA(author)Toreta
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 鄉(xiāng)村環(huán)境美化及設(shè)施建設(shè)合作協(xié)議
- 期房房屋買(mǎi)賣(mài)協(xié)議
- 2025-2030年中國(guó)餐飲連鎖行業(yè)運(yùn)營(yíng)市場(chǎng)深度調(diào)查及投資策略研究報(bào)告
- 2025-2030年中國(guó)非標(biāo)標(biāo)準(zhǔn)件市場(chǎng)需求現(xiàn)狀規(guī)劃研究報(bào)告
- 2025-2030年中國(guó)隔音玻璃產(chǎn)業(yè)運(yùn)營(yíng)狀況與發(fā)展?jié)摿Ψ治鰣?bào)告
- 2025-2030年中國(guó)防曬霜產(chǎn)業(yè)競(jìng)爭(zhēng)格局及發(fā)展盈利分析報(bào)告
- 2025-2030年中國(guó)鍵盤(pán)行業(yè)運(yùn)營(yíng)現(xiàn)狀及發(fā)展規(guī)劃分析報(bào)告
- 2025-2030年中國(guó)銅冶煉行業(yè)市場(chǎng)運(yùn)行趨勢(shì)及發(fā)展前景分析報(bào)告
- 2025-2030年中國(guó)針織面料行業(yè)發(fā)展?fàn)顩r及營(yíng)銷(xiāo)戰(zhàn)略研究報(bào)告
- 2025-2030年中國(guó)谷氨酸行業(yè)十三五規(guī)劃及發(fā)展前景分析報(bào)告
- (完整)PEP人教版小學(xué)生英語(yǔ)單詞四年級(jí)上冊(cè)卡片(可直接打印)
- 面神經(jīng)疾病課件
- 基本公共衛(wèi)生服務(wù)項(xiàng)目績(jī)效考核的課件
- 三年級(jí)下冊(cè)小學(xué)科學(xué)活動(dòng)手冊(cè)答案
- 國(guó)家電網(wǎng)有限公司十八項(xiàng)電網(wǎng)重大反事故措施(修訂版)
- 班、團(tuán)、隊(duì)一體化建設(shè)實(shí)施方案
- 最全的人教初中數(shù)學(xué)常用概念、公式和定理
- 橋面結(jié)構(gòu)現(xiàn)澆部分施工方案
- 開(kāi)網(wǎng)店全部流程PPT課件
- 人教部編版四年級(jí)語(yǔ)文下冊(cè)《第1課 古詩(shī)詞三首》教學(xué)課件PPT小學(xué)優(yōu)秀公開(kāi)課
- 模具數(shù)控加工技術(shù)概述
評(píng)論
0/150
提交評(píng)論