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.
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
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?
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.
Re: Is a trigger the best way to go