borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Image Sql?)Next Topic (can not use like in sql???) New Topic New Poll Post Reply
AndreaVB Forum : Database : trigger and trigger?
Poster Message
luckyboy
Level: VB Lord

Registered: 05-05-2005
Posts: 160

icon 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
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: trigger and trigger?

Hi,
As far as I am aware, you can have "instead of" triggers and so forth. Why would you need 2? Can't you just combine them into 1?
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

04-06-2006 at 09:52 PM
View Profile Send Email to User Show All Posts | Quote Reply
luckyboy
Level: VB Lord

Registered: 05-05-2005
Posts: 160
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
luckyboy
Level: VB Lord

Registered: 05-05-2005
Posts: 160
icon Re: trigger and trigger?

more idea pls? Pls?

____________________________
Please help out.

05-06-2006 at 03:37 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
luckyboy
Level: VB Lord

Registered: 05-05-2005
Posts: 160
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : trigger and trigger?
Previous Topic (Image Sql?)Next Topic (can not use like in sql???) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder