Vous êtes sur la page 1sur 2

Overview

Oracleletsyoudefineprocedurescalledtriggersthatrunimplicitlywhenan
INSERT,UPDATE,orDELETEstatementisissuedagainsttheassociatedtable
or,insomecases,againstaview,orwhendatabasesystemactionsoccur.These
procedurescanbewritteninPL/SQLorJavaandstoredinthedatabase.
Triggersaresimilartostoredprocedures.Atriggerstoredinthedatabasecan
includeSQLandPL/SQLorJavastatementstorunasaunitandcaninvokestored
procedures.Proceduresandtriggersdifferinthewaythattheyareinvoked.A
procedureisexplicitlyrunbyauser,application,ortrigger.Triggersareimplicitly
firedbyOraclewhenatriggeringeventoccursnomatterwhichuserisconnectedor
whichapplicationisbeingused.
Youcanwritetriggersthatfirewheneveroneofthefollowingoperationsoccurs:
1. DMLstatements(INSERT,UPDATE,DELETE)onaparticulartableor
view,issuedbyanyuser
2. DDLstatements(CREATEorALTERprimarily)issuedeitherbya
particularschema/userorbyanyschema/userinthedatabase
3. Databaseevents,suchaslogon/logoff,errors,orstartup/shutdown,alsoissued
eitherbyaparticularschema/userorbyanyschema/userinthedatabase
DDLtriggersandDMLtriggersareusedfordifferentpurposes.DMLtriggersand
DDLtriggersbothcanrunmanagedcodepackagedinanassemblythatwascreated
intheMicrosoft.NETFrameworkanduploadedinSQLServer.

DMLtriggersoperateonINSERT,UPDATE,andDELETEstatements,andhelpto
enforcebusinessrulesandextenddataintegritywhendataismodifiedintablesor
views.
DDLtriggersoperateonCREATE,ALTER,DROP,andotherDDLstatementsand
storedproceduresthatperformDDLlikeoperations.Theyareusedtoperform
administrativetasksandenforcebusinessrulesthataffectdatabases.Theyapplyto
allcommandsofasingletypeacrossadatabase,oracrossaserver.
DDLtriggersfirestoredproceduresinresponsetoanevent.DDLtriggersdonot
fireinresponsetoUPDATE,INSERT,orDELETEstatementsonatableorview.
Instead,theyfireinresponsetoavarietyofDataDefinitionLanguage(DDL)
events.TheseeventsprimarilycorrespondtoTransactSQLstatementsinSQL
serverthatstartwiththekeywordsCREATE,ALTER,andDROP.Certainsystem
storedproceduresthatperformDDLlikeoperationscanalsofireDDLtriggers.
DDLtriggerscanbeusedforadministrativetaskssuchasauditingandregulating
databaseoperations.DDLtriggerscanbeusedtopreventcertainchangestothe
databaseschema.DDLtriggerscanbeusedforsomethingtooccurinthedatabase
inresponsetoachangeinthedatabaseschema.DDLtriggerscanrecordchanges
oreventsinthedatabaseschema.DDLtriggersfireonlyaftertheDDLstatements
thattriggerthemarerun.DDLtriggerscannotbeusedasINSTEADOFtriggers.

Vous aimerez peut-être aussi