简体   繁体   中英

Notify application for inserted or deleted rows

I have an Microsoft SQL Server 2008 (SP3) running and would like to notify when some other out of reach application adds or removes rows from a certain table. I know that I can use triggers to manipulate data (sql) on inserted or deleted etc. But have no idea how to monitor the table and notify. The client that I want to build to display the notification can be a wpf xaml application, universal windows project or a web application. So the problem is the connection between monitoring the table and trigger sending some sort of notification (or a rest web call or something)

Do I need Notification Services or is there a better/easier way? Or would you suggest a CLR trigger ? Or a WPF Data trigger ? That seems the easiest to me.

edit My desired output would be a sort of monitoring application which displays something like this:

time, product code, quantity, removed/added something like this:

  • 9:45 am: 2 sharp tv's added
  • 10:15 am: 5 philips tv's removed
  • etc.

edit 2 a lot of suggestions for the SqlDependency but msdn says:

In general, most non-ASP.NET applications should use the SqlDependency object. ASP.NET applications should use the higher-level SqlCacheDependency, which wraps SqlDependency and provides a framework for administering the notification and cache objects.

But I do not see how I can view the removed rows. So perhaps make triggers to the table to insert a message product 123 removed 5 times in a message table. and product 456 added 15 times in the message table and then an sqldependency on the new to be created message table?

here audit is my table it raises some message when some thing happens on the table.

create trigger tr_audit_all on audit after delete,insert ,update
as begin
if exists (select 1 from inserted) and not exists (select 1 from deleted)
begin
print 'record inserted '
select * from inserted

end
if exists (select 1 from inserted) and exists (select 1 from deleted)
begin
raiserror( 'record inserted ',1,15)
end
if not exists (select 1 from inserted)and exists (select 1 from deleted )
begin
print 'record deleted '
end
end
drop trigger tr_audit_all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM