Results 1 to 4 of 4

Thread: Trigger Updating Same Table

  1. #1
    Join Date
    Oct 2002
    Posts
    16

    Trigger Updating Same Table

    Hi,

    I have a Insert / Update Trigger on Table called TBL_A. Inside the trigger I am updating the same table TBL_A.

    Will this cause recursion of the trigger? And will it keep on firing again and again?

    Thanks in advance ...jfk

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    Nope. just runs one time.
    example

    create table x (id int, name char(10))

    create trigger ins_tr on x for insert,update as
    update a set a.name = b.name from x a,inserted b
    where a.id =b.id
    print 'inserted'

  3. #3
    Join Date
    Sep 2002
    Posts
    23
    Unless the database is configured with recursive triggers turned ON. ALTER DATABASE SET RECURSIVE_TRIGGERS. Default is off, so the answer is "it depends"!

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    Nope.

    create table x (id int, name char(10))

    alter trigger ins_tr on x for insert,update as
    update a set a.name = b.name from x a,inserted b
    where a.id =b.id
    print 'inserted'


    alter database tempdb set RECURSIVE_TRIGGERS OFF
    insert into x select 110,'d'

    alter database tempdb set RECURSIVE_TRIGGERS ON
    insert into x select 110,'d'


    Both cases trigger gets executed only once. if it is inserting in another table which has trigger - it will fire.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •