Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

triggers Expand / Collapse
Author
Message
Posted Tuesday, December 16, 2008 4:24 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, January 19, 2009 2:19 PM
Points: 2, Visits: 2
hi there

this is my problem

i have a trigger defined on a table.
the code executed by this trigger is to check a column from the one in the (inserted or deleted tables) and then in my update that column with a default value in the originale table

for example

create trigger tr_name
on [my_table]
for update
as
update [my_table]
set [row_uid] = newid()
from [deleted] A
where A.[UID]=my_table.[UID]

in this case i have this trigger calling himself until it reashes 32 times, and i get an error.

i'm sure that the option recursive triggers is set to off for my DB

so what is wrong with this, or is there an other method to get the same result (update a column in the updated row from within the trigger)

thanks.
Post #620830
Posted Tuesday, December 16, 2008 6:42 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:44 AM
Points: 5,102, Visits: 20,206
What is your value for "nested triggers" option (ON or OFF)

Are they any other triggers on this table which update the table?

You might want to check BOL (Nested triggers) for SQL 2000 at:

http://msdn.microsoft.com/en-us/library/aa214644(SQL.80).aspx



If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #620854
Posted Tuesday, December 16, 2008 8:58 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, May 02, 2013 2:32 AM
Points: 2,236, Visits: 3,620
somewhat similar issue was posted earlier. You might want to refer that as well...

http://www.sqlservercentral.com/Forums/Topic618626-149-1.aspx#bm618684






Pradeep Singh
Post #620906
Posted Tuesday, December 16, 2008 9:00 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 5:47 AM
Points: 4,550, Visits: 8,201
Just don't update what does not need to be updated:
 update [my_table]
set [row_uid] = newid()
from [deleted] A
where A.[UID]=my_table.[UID]
and my_table.[row_uid] IS NULL

Post #620907
Posted Wednesday, December 17, 2008 7:21 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, May 17, 2013 12:22 PM
Points: 10,571, Visits: 11,871
Sergiy (12/16/2008)
Just don't update what does not need to be updated:
 update [my_table]
set [row_uid] = newid()
from [deleted] A
where A.[UID]=my_table.[UID]
and my_table.[row_uid] IS NULL



Assuming that my_table.UID is unique then the my_table.row_id Is Null should be unnecessary since there should only be 1 row affected per UID affected by the original update.

Either Nested triggers or recusive triggers must be ON because it should not fire itself otherwise.

To be honest, I actually looked at this one because I assumed the trigger would not handle sets, but it does so I am pretty happy.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #621208
Posted Wednesday, December 17, 2008 9:23 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, January 19, 2009 2:19 PM
Points: 2, Visits: 2
thans for your replays (all of you)

bitbucket (12/16/2008)
What is your value for "nested triggers" option (ON or OFF)

Are they any other triggers on this table which update the table?

You might want to check BOL (Nested triggers) for SQL 2000 at:

http://msdn.microsoft.com/en-us/library/aa214644(SQL.80).aspx



the recursive triggers option on my database is off.
i don't want to change the option on the server (because maybe there is a database witch needs the recursive option)
(i'm using SQL Server 2005)

an other question :
is there a difference between nested triggers and recursive triggers ?

thanks

Post #621360
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse