SQL Server Triggers have two unique objects that are not available except in Triggers. These are virtual tables named
deleted and
inserted. The deleted table contains rows that were deleted or the rows prior to update. The inserted table contains inserted rows or rows after the update.
These tables contain all of the columns of the table being updated. Thus if the table has a primary or unique key, say RecID, you can find the RecIDs in the Inserted table and have a unique key for each updated row.
You can extract a RecID with code like the following.
Declare @id int
Select @id=RecID From Inserted
Of course this only works if one records is updated unless you create a loop in code. You can also use the vitual tables in queries.
Archive records that have been changed;
Insert Into HistTable
Select * From Deleted
Update another table based on the Inserted table.
Update InventoryTbl
Set Qty = Qty - i.ShipQty
From InverntoryTbl t
Join Inserted i
On t.PartId=i.PartID
I hope this helps. Is it what you need to know?
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.