Home All Groups Group Topic Archive Search About

TRIGGER UPDATE QUESTION

Author
20 Jan 2006 6:52 PM
ReTF
Hi All,
If I have one UPDATE TRIGGER to table 'TA' and in this trigger I have one
UPDATE to the same table TA, this will stay in infinite loop?

Thaks

Author
20 Jan 2006 7:22 PM
Mark Williams
If you have the recursive triggers option set to ON, (true) then it could.

In SQL 2000, recursive triggers are disabled by default. Use ALTER DATABASE
to change the setting.

See "Using Nested Triggers" in BOL.

--



Show quote
"ReTF" wrote:

> Hi All,
> If I have one UPDATE TRIGGER to table 'TA' and in this trigger I have one
> UPDATE to the same table TA, this will stay in infinite loop?
>
> Thaks
>
>
>
Author
20 Jan 2006 7:30 PM
Stephen Hendricks
I believe that they will only fire to a depth of 32.

==================================================
People who want to share their religious views with you almost never
want you to share yours with them. -Dave Barry, author and columnist
(1947- )

*** Sent via Developersdex http://www.developersdex.com ***
Author
20 Jan 2006 8:17 PM
Alexander Kuznetsov
use pubs
go
ALTER DATABASE pubs
   SET RECURSIVE_TRIGGERS ON
go
drop table t
go
create table t(i int, j int)
insert into t values(1,1)
insert into t values(2,1)
insert into t values(3,1)
insert into t values(4,1)
go
drop trigger aaa
go
create trigger aaa
on t
for update
as
if @@nestlevel<10
begin
update t set j = t.j+inserted.j
from t,inserted where t.i=inserted.i+1 --and inserted.i<3 and t.j<2
end
go
update t set j=0 where i=1
go
select * from t

i           j
----------- -----------
1           0
2           1
3           2
4           3

(4 row(s) affected)

AddThis Social Bookmark Button