A trigger is a specification that the database should run automatically whenever a certain type of operation is performed. It can be defined to run or fire either before or after any INSERT
, UPDATE
, or DELETE
operation is performed on a particular object. This operation can be associated with a table, a view, a schema, or the database, and it is one of the following:
A Data Manipulation Language (DML) statement—
DELETE
,INSERT
, orUPDATE
A Data Definition Language (DDL) statement—
CREATE
,ALTER
, orDROP
A database operation—
SERVERERROR
,LOGON
,LOGOFF
,STARTUP
, orSHUTDOWN
Like a stored procedure, a trigger can be invoked repeatedly. A procedure is explicitly run by a user or an application but triggers are implicitly fired when a triggering event occurs, no matter which user is connected or which application is used. It can be enabled and disabled but you cannot explicitly invoke it. While a trigger is enabled, the database automatically invokes it—that is, the trigger...