Results 1 to 5 of 5

Thread: Is a trigger the best way to go [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Resolved Is a trigger the best way to go [Resolved]

    Hi, we have one local copy of a table stored in SQL Server and one website copy of a table stored in MySQL.
    At the end of the night I want all changes to the SQL server updated to the website on this table.
    I thought in my very limited knowledge that a trigger might be the way to go. The trigger would tell me which SQL Server columns had been changed as follows

    Code:
    Create trigger dbo.testtrig on dbo.employees for update
    as
    begin
    declare @empid int
    declare @webup bit
    set @webup = (select Webupdate from inserted)
    If  @webup = 0
    
    set @empid = (select employeesID from inserted)
    update employees set webupdate = 1 where employeesID = @empid
    end
    I'd then just update the columns that had 1 for webupdate.
    Does this make sense, or is this a crazy way to do things.
    Basically does the above trigger look correct and what improvments can I make or a better way of doing the same thing would be good.
    Last edited by Oliver1; Jan 17th, 2006 at 12:20 PM. Reason: Typo

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Is a trigger the best way to go

    This should do the same thing in one line:

    Code:
    Create trigger dbo.testtrig on dbo.employees for update
    as
    begin
    Update Employees Set WebUpdate=1
     From Employees EM
     Left Join Inserted IR on IR.EmployeesId=EM.EmployeesId
     Where IR.WebUpdate=0
    end

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Re: Is a trigger the best way to go

    Thanks, works great on my test system.
    So what I'm doing doesn't sound that crazy?

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Is a trigger the best way to go

    Quote Originally Posted by Oliver1
    Thanks, works great on my test system.
    So what I'm doing doesn't sound that crazy?
    Seems like it's a requirement for you - so basically I see no way around it.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Re: Is a trigger the best way to go

    Thanks

Posting Permissions

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



Click Here to Expand Forum to Full Width