INSERT INTO audit (trackingUser, date_time)
select SYSTEM_USER, getdate()
from Inserted I
inner join Deleted D on D.id = I.id /* Use your PK condition */
where <some condition that compares fields in I & D>
РЕДАКТИРОВАТЬ: На основе вашего комментария вы можете захотеть:
create trigger AuditTrigger2 on authors
AFTER insert,update,delete
AS
begin
-- Handle Insert
INSERT INTO audit (trackingUser, date_time, trasactionType)
select SYSTEM_USER, getdate(), 'inserted'
from Inserted I
where not exists (select 1 from Deleted)
and <some condition that compares fields in I & D>
-- Handle Delete
INSERT INTO audit (trackingUser, date_time, trasactionType)
select SYSTEM_USER, getdate(), 'deleted'
from Deleted I
where not exists (select 1 from Inserted)
and <some condition that compares fields in I & D>
-- Handle Update
INSERT INTO audit (trackingUser, date_time, trasactionType)
select SYSTEM_USER, getdate(), 'updated'
from Inserted I
inner join Deleted D on D.id = I.id /* Use your PK condition */
where <some condition that compares fields in I & D>
end
go