已阅读5页,还剩40页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
2013pearsoneducation,inc.publishingasprenticehall,1,chapter7:advancedsql,moderndatabasemanagement11theditionjeffreya.hoffer,v.ramesh,heikkitopi,definetermswritesingleandmultipletablesqlqueriesdefineandusethreetypesofjoinswritenoncorrelatedandcorrelatedsubqueriesunderstandandusesqlinprocedurallanguages(e.g.php,pl/sql)understandtriggersandstoredproceduresdiscusssql:2008standardanditsenhancementsandextensions,2,objectives,processingmultipletables,joinarelationaloperationthatcausestwoormoretableswithacommondomaintobecombinedintoasingletableorviewequi-joinajoininwhichthejoiningconditionisbasedonequalitybetweenvaluesinthecommoncolumns;commoncolumnsappearredundantlyintheresulttablenaturaljoinanequi-joininwhichoneoftheduplicatecolumnsiseliminatedintheresulttable,3,thecommoncolumnsinjoinedtablesareusuallytheprimarykeyofthedominanttableandtheforeignkeyofthedependenttablein1:mrelationships.,processingmultipletables,outerjoinajoininwhichrowsthatdonothavematchingvaluesincommoncolumnsarenonethelessincludedintheresulttable(asopposedtoinnerjoin,inwhichrowsmusthavematchingvaluesinordertoappearintheresulttable)unionjoinincludesallcolumnsfromeachtableinthejoin,andaninstanceforeachrowofeachtable,4,5,figure7-2visualizationofdifferentjointypeswithresultsreturnedinshadedarea,thefollowingslidescreatetablesforthisenterprisedatamodel,6,(fromchapter1,figure1-3),7,thesetablesareusedinqueriesthatfollow,figure7-1pinevalleyfurniturecompanycustomer_tandorder_ttableswithpointersfromcustomerstotheirorders,7,chapter7,2013pearsoneducation,inc.publishingasprenticehall,equi-joinexample,foreachcustomerwhoplacedanorder,whatisthecustomersnameandordernumber?,8,customeridappearstwiceintheresult,equi-joinexamplealternativesyntax,9,innerjoinclauseisanalternativetowhereclause,andisusedtomatchprimaryandforeignkeys.aninnerjoinwillonlyreturnrowsfromeachtablethathavematchingrowsintheother.thisqueryproducessameresultsaspreviousequi-joinexample.,naturaljoinexample,foreachcustomerwhoplacedanorder,whatisthecustomersnameandordernumber?,10,note:fromfig.7-1,youseethatonly10customershavelinkswithorders.only10rowswillbereturnedfromthisinnerjoin,outerjoinexample,listthecustomername,idnumber,andordernumberforallcustomers.includecustomerinformationevenforcustomersthatdohaveanorder.,11,unlikeinnerjoin,thiswillincludecustomerrowswithnomatchingorderrows,12,outerjoinresults,unlikeinnerjoin,thiswillincludecustomerrowswithnomatchingorderrows,12,chapter7,2013pearsoneducation,inc.publishingasprenticehall,multipletablejoinexample,assembleallinformationnecessarytocreateaninvoiceforordernumber1006,13,14,figure7-4resultsfromafour-tablejoin(editedforreadability),self-joinexample,15,thesametableisusedonbothsidesofthejoin;distinguishedusingtablealiases,self-joinsareusuallyusedontableswithunaryrelationships.,16,figure7-5exampleofaself-join,processingmultipletablesusingsubqueries,subqueryplacinganinnerquery(selectstatement)insideanouterqueryoptions:inaconditionofthewhereclauseasa“table”ofthefromclausewithinthehavingclausesubqueriescanbe:noncorrelatedexecutedoncefortheentireouterquerycorrelatedexecutedonceforeachrowreturnedbytheouterquery,17,subqueryexample,showallcustomerswhohaveplacedanorder,18,theinoperatorwilltesttoseeifthecustomer_idvalueofarowisincludedinthelistreturnedfromthesubquery,joinvs.subquery,somequeriescouldbeaccomplishedbyeitherajoinorasubquery,19,joinversion,subqueryversion,20,figure7-6graphicaldepictionoftwowaystoansweraquerywithdifferenttypesofjoins,21,figure7-6graphicaldepictionoftwowaystoansweraquerywithdifferenttypesofjoins,correlatedvs.noncorrelatedsubqueries,noncorrelatedsubqueries:donotdependondatafromtheouterqueryexecuteoncefortheentireouterquerycorrelatedsubqueries:makeuseofdatafromtheouterqueryexecuteonceforeachrowoftheouterquerycanusetheexistsoperator,22,23,figure7-8aprocessinganoncorrelatedsubquery,anoncorrelatedsubqueryprocessescompletelybeforetheouterquerybegins.,23,chapter7,2013pearsoneducation,inc.publishingasprenticehall,correlatedsubqueryexample,showallordersthatincludefurniturefinishedinnaturalash.,24,acorrelatedsubqueryalwaysreferstoanattributefromatablereferencedintheouterquery,25,figure7-8bprocessingacorrelatedsubquery,subqueryreferstoouter-querydata,soexecutesonceforeachrowofouterquery,note:onlytheordersthatinvolveproductswithnaturalashwillbeincludedinthefinalresults.,25,chapter7,2013pearsoneducation,inc.publishingasprenticehall,anothersubqueryexample,showallproductswhosestandardpriceishigherthantheaverageprice,26,unionqueries,combinetheoutput(unionofmultiplequeries)togetherintoasingleresulttable,27,28,figure7-9combiningqueriesusingunion,note:withunionqueries,thequantityanddatatypesoftheattributesintheselectclausesofbothqueriesmustbeidentical.,28,chapter7,2013pearsoneducation,inc.publishingasprenticehall,conditionalexpressionsusingcasesyntax,thisisavailablewithnewerversionsofsql,previouslynotpartofthestandardfigure7-10,29,tipsfordevelopingqueries,befamiliarwiththedatamodel(entitiesandrelationships)understandthedesiredresultsknowtheattributesdesiredinresultsidentifytheentitiesthatcontaindesiredattributesreviewerdconstructawhereequalityforeachlinkfinetunewithgroupbyandhavingclausesifneededconsidertheeffectonunusualdata,30,queryefficiencyconsiderations,insteadofselect*,identifythespecificattributesintheselectclause;thishelpsreducenetworktrafficofresultsetlimitthenumberofsubqueries;trytomakeeverythingdoneinasinglequeryifpossibleifdataistobeusedmanytimes,makeaseparatequeryandstoreitasaview,31,guidelinesforbetterquerydesign,understandhowindexesareusedinqueryprocessingkeepoptimizerstatisticsup-to-dateusecompatibledatatypesforfieldsandliteralswritesimplequeriesbreakcomplexqueriesintomultiplesimplepartsdontnestonequeryinsideanotherquerydontcombineaquerywithitself(ifpossibleavoidself-joins),32,guidelinesforbetterquerydesign(cont.),createtemporarytablesforgroupsofqueriescombineupdateoperationsretrieveonlythedatayouneeddonthavethedbmssortwithoutanindexlearn!considerthetotalqueryprocessingtimeforadhocqueries,33,ensuringtransactionintegrity,transaction=adiscreteunitofworkthatmustbecompletelyprocessedornotprocessedatallmayinvolvemultipleupdatesifanyupdatefails,thenallotherupdatesmustbecancelledsqlcommandsfortransactionsbegintransaction/endtransactionmarksboundariesofatransactioncommitmakesallupdatespermanentrollbackcancelsupdatessincethelastcommit,34,35,figure7-12ansqltransactionsequence(inpseudocode),35,chapter7,2013pearsoneducation,inc.publishingasprenticehall,datadictionaryfacilities,systemtablesthatstoremetadatausersusuallycanviewsomeofthesetablesusersarerestrictedfromupdatingthemsomeexamplesinoracle11gdba_tablesdescriptionsoftablesdba_constraintsdescriptionofconstraintsdba_usersinformationabouttheusersofthesystemexamplesinmicrosoftsqlserver2008sys.columnstableandcolumndefinitionssys.indexestableindexinformationsys.foreign_key_columnsdetailsaboutcolumnsinforeignkeyconstraints,36,sql:2008enhancements/extensions,user-defineddatatypes(udt)subclassesofstandardtypesoranobjecttypeanalyticalfunctions(forolap)ceiling,floor,sqrt,rank,dense_rank,rollup,cube,sample,windowimprovednumericalanalysiscapabilitiesnewdatatypesbigint,multiset(collection),xmlcreatetablelikecreateanewtablesimilartoanexistingonemerge,37,programmingextensionspersistentstoredmodules(sql/psm)capabilitytocreateanddropcodemodulesnewstatements:case,if,loop,for,while,etc.makessqlintoaprocedurallanguageoraclehasproprietyversioncalledpl/sql,andmicrosoftsqlserverhastransact/sql,38,sql:2008enhancements(cont),routinesandtriggers,routinesprogrammodulesthatexecuteondemandfunctionsroutinesthatreturnvaluesandtakeinputparametersproceduresroutinesthatdonotreturnvaluesandcantakeinputoroutputparameterstriggersroutinesthatexecuteinresponsetoadatabaseevent(insert,update,ordelete),39,40,figure7-13triggerscontras
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 应急类面试试题及答案
- 建筑环境与设备工程笔试试题及答案
- 心理咨询师试题及答案
- 报检员 测试第9章第1节模拟考题和答案解析
- 教师招聘考试教育法律法规试题库及答案
- 教育强国考试试题及答案
- 2025 年大学计算机科学与技术(计算机组成原理)试题及答案
- 数字推理错题集锦
- 文明礼仪知识测试题
- 无极县社区工作者招聘真题2024
- 汽车机械制图(第二版)试题试卷及答案2套
- 某某市畜牧路供热管网工程全套资料表格
- 物业工程夜班岗位职责
- 产品经理笔面试经典题型分享-费米问题
- 学校校服选用采购会议记录
- 备考2024年中考数学专题突破(全国通用)专题2-3 八种隐圆类最值问题圆来如此简单(解析版)
- 山东省精神卫生中心招聘试题及解析
- 企业员工廉洁行为规范培训课件
- JT-T 795-2023 事故汽车修复技术规范
- 国家开放大学《数据结构》课程实验报告(实验2-线性表)参考答案
- DBJ50-200-2014建筑桩基础设计与施工验收规范
评论
0/150
提交评论