Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Erstellen Sie einen Trigger für mehrere Vorgänge

Macht nichts, ich habe es verstanden :

Create trigger [dbo].[TR_AUDIT_TESTAUDIT]
    ON [dbo].[testaudit]
    AFTER INSERT, UPDATE, DELETE 
    AS 
BEGIN
    SET NOCOUNT ON;
    declare @action nvarchar(1) 

    set @action = 'I' -- always I 

    if exists(select top 1 1 from deleted) and not exists(select top 1 1 from inserted)         
    set @action = 'D' 

    if exists(select top 1 1 from deleted) and  exists(select top 1 1 from inserted)        
    set @action = 'U'        
END