




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025黑龙江哈尔滨春季“丁香人才周”市场监督管理局事业单位引才招聘20人考前自测高频考点模拟试题及答案详解(典优)
- 2025河南中豫建设投资集团股份有限公司招聘1人考前自测高频考点模拟试题附答案详解(突破训练)
- 2025贵州铜仁市科技创新成果转化中心引进专业技术人才模拟试卷及参考答案详解一套
- 2025北京丰台区新村街道办事处招聘城市协管员6人模拟试卷及答案详解(历年真题)
- 2025年甘肃庆阳庆城县事业单位引进高层次和急需紧缺人才(第三批)模拟试卷及一套答案详解
- 2025昆明市五华区某政府单位行政辅助岗位人员招聘(2人)考前自测高频考点模拟试题及答案详解参考
- 2025广东茂名市供销集团有限公司招聘10人模拟试卷及答案详解(各地真题)
- 2025江苏常州纺织服装职业技术学院招聘辅导员6人模拟试卷及答案详解(必刷)
- 2025年高级纤维检验员《理论知识》考试真题(含解析)
- 2025河北保定市雄安新区雄县事业单位招聘89人模拟试卷附答案详解
- 《商业文化》课件-第3章 古代商贤及其商业文化
- 七十岁老人三力测试题
- 小儿结核病教案
- 【高二 拓展阅读-科技】Wind Energy
- 我的家乡滕州市宣传简介
- 法院起诉收款账户确认书范本
- 15ZJ001 建筑构造用料做法
- 初中历史小论文现状分析与写作探讨
- 燕山石化聚丙烯工艺综述最好实习报告内容
- 自考05175税收筹划(15-19)真题试卷
- 微机原理与接口技术(清华大学课件,全套)
评论
0/150
提交评论