Advertisement

04.07.2008 at 01:08AM PDT, ID: 23300687
[x]
Attachment Details

Infinite loop in triggers, on update

Asked by Mezillinu in MS SQL Server

I have these triggers, that are done on many tables. Could these cause an infinite loop the way I have coded them? I want the latest update to be set to the getdate() on insert and on update. Is there any way I could improve them? Becuase I think they are causing an infinite loop, because when an update has been made, the trigger acts as an update, and then when the update has been made, the trigger is acting again I think...

Is this possible, the way I have coded them? I am a beginner on coding triggers, so any help is appreciated!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
--this will create the latest update field in table_publishpointcategory
 
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TBL_publishpoint' AND COLUMN_NAME = 'LATEST_UPDATE')
BEGIN
   ALTER TABLE tbl_publishpoint ADD LATEST_UPDATE DATETIME null
END
 
GO
 
IF EXISTS (SELECT name FROM sysobjects WHERE  name = 'tbl_publishpoint_last_Updated' 
        AND    type = 'TR')
     DROP TRIGGER tbl_publishpoint_last_Updated
 GO
 
CREATE TRIGGER [tbl_publishpoint_last_Updated] 
   ON  [dbo].[tbl_publishpoint] 
   FOR update
AS 
BEGIN
UPDATE tbl_publishpoint
		SET latest_update = getdate()
			FROM inserted as i
				JOIN tbl_publishpoint ON tbl_publishpoint.pubpointcatid = i.pubpointcatid
END
[+][-]04.07.2008 at 01:17AM PDT, ID: 21295047

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.07.2008 at 01:22AM PDT, ID: 21295067

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 01:25AM PDT, ID: 21295078

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 01:29AM PDT, ID: 21295100

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 01:55AM PDT, ID: 21295210

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 08:40AM PDT, ID: 21297963

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.07.2008 at 09:38AM PDT, ID: 21298496

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 09:50AM PDT, ID: 21298597

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 06:44AM PDT, ID: 21305136

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 10:46AM PDT, ID: 21307723

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 03:16PM PDT, ID: 21310151

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 11:35PM PDT, ID: 21312260

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.09.2008 at 07:40AM PDT, ID: 21315395

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628