Beruflich Dokumente
Kultur Dokumente
Implementing Triggers
Introduction to Triggers
Defining Triggers
How Trigger Works
Performance Considerations
Introduction to Triggers
Create
Create Trigger
Trigger t_tdate
t_tdate
ON
ON tdate
tdate Table Name
FOR
FOR Delete
Delete
as
as
set
set nocount
nocount on on Trigger Action
delete
delete from
from tdate
tdate
begin
begin
print
print ' ' You
You can
can not
not delete
delete from
from table
table tdate'
tdate'
rollback
rollback transaction
transaction
end
end
How Triggers Work
Use
Use Triggers
Triggers Only
Only When
When Necessary
Necessary
Keep
Keep Definitions
Definitions as
as Simple
Simple as
as Possible
Possible
Minimize
Minimize Use
Use of
of ROLLBACK
ROLLBACK in
in Triggers
Triggers
Check Your Understanding.
Q.1 What is a Trigger.?
Q.2. Triggers are powerful tools that can be used to
enforce business rules automatically when data is
modified. ?
1. True
2. False
Q.3. A Trigger can be Associated with a Table or View.?
1. Yes
2. No
Q.4. Triggers Are Proactive ; Constraints Are Reactive.
1. True
2. False
Q.5. Name the Logical Tables that the part of SQL Server
Trigger Architecture.
Q.6. What is the role of Inserted Table when
Insert Trigger fires.
Q.7. What is the role of Deleted Table when Deleted
Trigger fires.
Q.8. How an Update Trigger use logical tables differently
than other DML Statements.
Q.9. Are there other DML Statements also which
can make a trigger to fire.
1. Yes
2. No
Q.10. A trigger can be called directly.
1. True
2. False
Q.11. You are a consultant tasked with troubleshooting a
client's database. The client has a trigger that is used
to enforce complex referential integrity. The trigger
references columns in several tables and performs a
cascading update. The client has tried several times,
but the trigger does not execute. What is the most
likely cause?
Introduction to Triggers
Defining Triggers
How Trigger Works
Performance Considerations
Thank You.