 |
luckyboy Level: VB Lord
 Registered: 05-05-2005 Posts: 160
|
trigger and trigger?
hi all. i want a trigger that can do in loop. for example:
my trigger T1 is update table A when i insert table A. and then my other trigger T2 is update table A when i update table A. this is possible to have trigger like that? could anyone help me please?
____________________________
Please help out.
|
|
04-06-2006 at 10:57 AM |
|
|
luckyboy Level: VB Lord
 Registered: 05-05-2005 Posts: 160
|
Re: trigger and trigger?
ok. i will combine them into 1. then, this is possible to have trigger like that? more ideas please?
____________________________
Please help out.
|
|
05-06-2006 at 03:39 AM |
|
|
luckyboy Level: VB Lord
 Registered: 05-05-2005 Posts: 160
|
Re: trigger and trigger?
more idea pls? Pls?
____________________________
Please help out.
|
|
05-06-2006 at 03:37 PM |
|
|
stickleprojects Level: Moderator

 Registered: 09-09-2002 Posts: 891
|
Re: trigger and trigger?
Hi, [from memory as I am not at work with my sql server]
the code to create a trigger is:
CREATE TRIGGER ON mytablename FOR UPDATE, INSERT, DELETE
BEGIN
END
|
Within the trigger you may put all the commands you wish. An UPDATE counts as both an INSERT and a DELETE.
For example, to count the records for an update:
DECLARE @inserted int, @deleted int, @updated int
SELECT @inserted = count(*) from inserted
SELECT @deleted = count(*) from deleted
SELECT @updated =count(*) FROM
inserted i
inner join
deleted d on (i.keyfield1=d.keyfield1)
|
Can you explain what you are doing. If you could supply the SQL you are trying to run in 2 triggers, I'll merge it into 1 for you.
Hope this helps,
Kieron
____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)
|
|
05-06-2006 at 05:59 PM |
|
|
luckyboy Level: VB Lord
 Registered: 05-05-2005 Posts: 160
|
Re: trigger and trigger?
it is recursive trigger.
CREATE TRIGGER UpdateStudent On tblStudent FOR Update as
DECLARE @studentid int
SELECT @studentid=studentReg FROM tblStudent WHERE Status=2
UPDATE tblStudent SET Status=2 WHERE StudentID=StudentID
UPDATE tblStudent SET Status=0 WHERE StudentReg=@StudentID
|
if in tblstudent still have status =2, this trigger will never end.
more idea pls?
____________________________
Please help out.
|
|
06-06-2006 at 01:31 AM |
|
|
|
|
 |
 |