Help me create this Trigger

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Leonardo Almeida

    Help me create this Trigger



    Hi everybody,

    How can I Update a field from another table by Trigger? Can someone send
    me the statment to do it?

    I have a table called Clients with fields : ID_Clients, Client
    And Another called Doc with fields : ID_Doc, ID_Clients, Client

    These tables are in different databases and I would like to esure the
    integrity by add a Trigger to update in Doc´s table the field Client
    everytime it´s changed in the Client´s table.

    Thanks for Attetion.

    Leonardo Almeida



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Simon Hayes

    #2
    Re: Help me create this Trigger


    "Leonardo Almeida" <leonardoalmeid a2004@yahoo.com .br> wrote in message
    news:3f672aa2$0 $62077$75868355 @news.frii.net. ..[color=blue]
    >
    >
    > Hi everybody,
    >
    > How can I Update a field from another table by Trigger? Can someone send
    > me the statment to do it?
    >
    > I have a table called Clients with fields : ID_Clients, Client
    > And Another called Doc with fields : ID_Doc, ID_Clients, Client
    >
    > These tables are in different databases and I would like to esure the
    > integrity by add a Trigger to update in Doc´s table the field Client
    > everytime it´s changed in the Client´s table.
    >
    > Thanks for Attetion.
    >
    > Leonardo Almeida
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]

    Something like this should work:

    create trigger dbo.ATR_U_Clien ts
    on dbo.Clients
    after update
    as

    if @@rowcount = 0
    return

    update OtherDatabase.d bo.Doc
    set Client = i.Client
    from OtherDatabase.d bo.Doc d
    join inserted i
    on d.ID_Clients = i.ID_Clients


    Simon


    Comment

    Working...