PART2RELATIONALDATABASESChapter8ApplicationDesignandDevelopmentApril2009DatabaseSystemConcepts-Chapter8ApplicationDesignandDevelopment-3CasestudyusedinthischapterreturnFig.8.0SchemaofbankingenterpriseApril2009DatabaseSystemConcepts-Chapter8ApplicationDesignandDevelopment-4§8.6Trigger(触发器)TriggerastatementthatisexecutedautomaticallybyDBMSasasideeffectofamodificationtothedatabaseAsanintegritycontrolmechanism,TriggerisintroducedtoSQL1999standard,butsupportedevenearlierusingnon-standardsyntaxbymostdatabasesApril2009DatabaseSystemConcepts-Chapter8ApplicationDesignandDevelopment-58.6Trigger(cont.)Triggerisanevent-condition-actionmodelbasedintegritydefinition,checking,remedymechanismspecifywhateventscausethetriggertobeexecuted(e.g.insert,delete,update),andunderwhichconditionsthetriggerexecutionwillproceedintegrityconstraintscheckingspecifytheactionstobetakenwhenthetriggerexecutesifconstraintsisviolated,remedyactionsaretakenApril2009DatabaseSystemConcepts-Chapter8ApplicationDesignandDevelopment-6Supposethat,insteadofallowingnegativeaccountbalances,thebankdealswithoverdrafts(透支)byfollowingactionssettingtheaccountbalancetozerocreatingaloanintheamountoftheoverdraftgivingthisloanaloannumberidenticaltotheaccountnumberoftheoverdrawnaccountTriggeroverdraft-triggerinFig.8.8thetriggeringeventisupdateonbalancetheconditionforexecutingthetriggerisanmodificationtotheaccountrelationthatresultsinanegativebalancevalueExampleOneApril2009DatabaseSystemConcepts-Chapter8ApplicationDesignandDevelopment-7triggeractionsareinsertonborrower,loanrelations,andupdateonaccountrelationExampleOne(cont.)createtriggeroverdraft-triggerafterupdateonaccount---eventreferencingnewrowasnrowforeachrowwhennrow.balance<0-------conditionbeginatomic-------actioninsertintoborrower(selectcustomer-name,account-numberfromdepositorwherenrow.account-number=depositor.account-number);insertintoloanvalues(nrow.account-number,nrow.branch-name,–nrow.balance);updateaccountsetbalance=0w...