C# / SQL Listener to tell me if a row has been inserted into a table

前端 未结 7 1122
傲寒
傲寒 2020-12-15 10:44

Can someone post sample code or tell me how to set up a listener to notify me (trigger an event) if a new row is inserted into a SQL Server database?

I don\'t want

7条回答
  •  再見小時候
    2020-12-15 11:20

    Trigger sounds best option:

    create TRIGGER [tI_Notifier] ON [dbo].[your_table_name] AFTER INSERT
    AS 
    BEGIN
        SET NOCOUNT ON;
    
        declare @id1 int --or same type as your key
            --declare other variables you want to read from the inserted row
    
            --read columns values from inserted row
        select @id1 = , @id2= from inserted
    
        --do something with row's new values
    
        SET NOCOUNT OFF;
    END
    

提交回复
热议问题