




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 生产酒瓶销售合同范本
- 承包荒山流转合同范本
- 嫁接果树售卖合同范本
- 社工站站长合同范本
- 餐饮加盟投资合同范本
- 单位汽车出租合同范本
- 深圳购房预售合同范本
- 租赁渔场合同范本
- 管道经销合同范本
- 物流报关合同范本
- 退伍留疆考试题库及答案
- 小学四年级数学口算题(每页60道直接打印).文档
- 诱思探究理论
- 铣床日常点检保养记录表
- 农产品贮藏与加工教案
- 04某污水处理厂630kW柔性支架光伏发电项目建议书
- 2022中国移动通信集团重庆限公司招聘上岸笔试历年难、易错点考题附带参考答案与详解
- 北师大版九年级数学上九年级第一二单元综合数学试题
- 二级建造师成绩复核申请
- GB/T 25702-2010复摆颚式破碎机颚板磨耗
- GB 29541-2013热泵热水机(器)能效限定值及能效等级
评论
0/150
提交评论