|
-
Jan 17th, 2006, 11:30 AM
#1
Thread Starter
Hyperactive Member
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
-
Jan 17th, 2006, 12:03 PM
#2
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
-
Jan 17th, 2006, 12:13 PM
#3
Thread Starter
Hyperactive Member
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?
-
Jan 17th, 2006, 12:16 PM
#4
Re: Is a trigger the best way to go
 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.
-
Jan 17th, 2006, 12:20 PM
#5
Thread Starter
Hyperactive Member
Re: Is a trigger the best way to go
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|