Trigger problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Manoj S. P.

    Trigger problem

    Hi Folks,

    My basic requirement is I want to write a trigger on a table based on
    certain conditions post-update from another table in another database.

    The actors in this scenario are:
    Database D1, Table T1
    Database D2, Table T2, T3

    Action:
    T1 updates T2

    Requirement:
    As soon as T2 is updated, I need to trigger an insert onto T3.
    However, I do not want this action to be performed on every update on
    T2 (other sources also update T2).
    I want the trigger only for updates from T1.
    I do not know how to go about it (conditional syntax for the update?)

    I urgently require to solve this problem.
    Thanks in advance for all those pitching in with help.

    Best Regards,
    Manoj S. Panicker
  • Manoj S. P.

    #2
    Re: Trigger problem

    Sorry I forgot to include the version of MS-SQL server. It is MS-SQL 7.0.


    manoj@direct2s. com (Manoj S. P.) wrote in message news:<26ec7b68. 0310162246.bba3 56e@posting.goo gle.com>...[color=blue]
    > Hi Folks,
    >
    > My basic requirement is I want to write a trigger on a table based on
    > certain conditions post-update from another table in another database.
    >
    > The actors in this scenario are:
    > Database D1, Table T1
    > Database D2, Table T2, T3
    >
    > Action:
    > T1 updates T2
    >
    > Requirement:
    > As soon as T2 is updated, I need to trigger an insert onto T3.
    > However, I do not want this action to be performed on every update on
    > T2 (other sources also update T2).
    > I want the trigger only for updates from T1.
    > I do not know how to go about it (conditional syntax for the update?)
    >
    > I urgently require to solve this problem.
    > Thanks in advance for all those pitching in with help.
    >
    > Best Regards,
    > Manoj S. Panicker[/color]

    Comment

    • Erland Sommarskog

      #3
      Re: Trigger problem

      [posted and mailed, please reply in news]

      Manoj S. P. (manoj@direct2s .com) writes:[color=blue]
      > My basic requirement is I want to write a trigger on a table based on
      > certain conditions post-update from another table in another database.
      >
      > The actors in this scenario are:
      > Database D1, Table T1
      > Database D2, Table T2, T3
      >
      > Action:
      > T1 updates T2
      >
      > Requirement:
      > As soon as T2 is updated, I need to trigger an insert onto T3.
      > However, I do not want this action to be performed on every update on
      > T2 (other sources also update T2).
      > I want the trigger only for updates from T1.
      > I do not know how to go about it (conditional syntax for the update?)[/color]

      If I understand this correctly, you have a trigger on T1 that updates T2,
      and when T2 is updated through this trigger you want to cascade to T3,
      but not when T2 is updated from other places.

      This is a kind of odd thing to do, but it is actually possible. In T1
      create a temp table, call it #do$updateT3, and in T2 you do:

      IF object_id('temp db..#do$updateT 3') IS NOT NULL
      UPDATE T3 ...

      It doesn't matter what columns you have in the temp table, or if
      there is any data. It's the table itself that serves as a global
      flag variable.


      --
      Erland Sommarskog, SQL Server MVP, sommar@algonet. se

      Books Online for SQL Server SP3 at
      SQL Server 2025 redefines what's possible for enterprise data. With developer-first features and integration with analytics and AI models, SQL Server 2025 accelerates AI innovation using the data you already have.

      Comment

      Working...