For a simple sql-server update trigger, I may write a class like this:
[Microsoft.SqlServer.Server.SqlTrigger (Name="MyTrigger", Target="[dbo].[MyTable]", Event="FOR UPDATE")]
public static void MyTrigger() { //... my code }
But if I only want to trigger on one column update, that would that behave like :
create trigger myTrigger
on myTable
for update as
if update(MyColumn)
begin
-- my code
end
what kind of Microsoft.SqlServer.Server.SqlTrigger attribute should I use ?
May be this could help you.
You cannot prevent running the trigger selectively, it will always run no matter the columns updated. However, once launched you can consult the COLUMNS_UPDATED() function:
So you would adjust your trigger logic to have appropiate action according to what columns where updated.
That being said, calling WCF from SQLCLR is a very very bad idea. Calling WCF from a trigger is even worse. Your server will die in production as transactions will block/abort waiting on some HTTP response to crawl back across the wire. Not to mention that your calls are inherently incorrect in presence of rollbacks, as you cannot undo an HTTP call. The proper way to do such actions is to decouple the operation and the WCF call by means of a queue. You can do this with tables used as queues, you could use true queues or you could use Change Tracking. Any of these would allow you to decouple the change and the WCF call and would allow you to make the call from a separate process, not from SQLCLR
Source: CLR Trigger only particular column get updated