This topics is picked from Microsoft Business Intelligence (Data Tools) - Triggers.
Difference
between Trigger and Stored Procedures
Contents
|
Triggers
|
Stored Procedures
|
Implementation
|
Triggers can only be
implemented on tables or views.
A trigger cannot be
written within a stored procedure.
|
Stored Procedure in
independent code that can be specific to database.
A stored procedure can
be written within a trigger
|
Event and action
|
Triggers are event and
action based to perform some specific tasks and they are free to run
automatically whenever the event is occurred on the table on which the
trigger is defined
|
They are not based on
the event and action. They are not able to run automatically and depend on
the other manual process.
|
Execution Mode
|
They execute implicitly.
|
A stored procedure
must be called explicitly.
|
Schedule Mode
|
This is not possible
for triggers because they are event and action based.
|
Stored procedures can
be easily scheduled through a job to execute on a predefined time.
|
Transactions
|
Transactions are not allowed
in Triggers.
|
Transaction statements
like begin transaction, commit transaction, and rollback can be used easily
inside a stored procedure.
|
Parameters
|
This feature is not
applicable in triggers.
|
Stored Procedures may
or may not have one or more input/ output parameters to perform some tasks.
|
Front end applications
|
This feature is not
applicable for triggers.
|
Stored Procedures can
be easily called from the front end (.asp files, .aspx files, .ascx files,
.rdl etc.)
|
Return Value specific
|
A trigger cannot
return a value.
|
Stored procedures can
return values.
|
Debugging
|
Print commands cannot
work inside the trigger.
|
Print commands can
work inside a stored procedure for debugging purposes.
|
Nesting
|
Directly you cannot call
another trigger within a trigger.
|
A stored procedure can
be called from inside another stored procedure.
|
Task Specific
|
The Triggers for
auditing work: Triggers normally are used for auditing work. They can be used
to trace the activities of table events.
|
Stored procedures are
used for performing tasks. Stored procedures are normally used for performing
user specified tasks.
|
To know more about SQL - Triggers.
No comments:
Post a Comment