List members for "inserted" and "deleted" pseudo tables in trigger body
Version 3.0 is on the site
-
invm commented
Had in mind pseudo-tables "inserted" and "deleted". They are used in triggers and DML-statements with output clause. For example:
1. trigger
/*Simple logging trigger*/
create trigger dbo.trWriteJournal
on dbo.TestTable
for insert, update, delete
as
begin
insert into dbo.TestTable_Journal
(row_id, Value_Old, Value_New)
select
coalesce(i.row_id, d.row_id, d.Value, i.Value)
from
inserted i full join
deleted d on d.row_id = i.row_id
end2. DML-statement with output clause
update dbo.TestTable
set
Value = Value + 1
output
deleted.Value, inserted.Value into dbo.AnotherTestTable (Value1, Value2)
where
row_id between 1 and 100