Handling an Update
This is great if you want to keep a history of changes made to a table. With a little
bit of work you can chage the temp table used below into a permanent table in the
database to track the changes made to your table. This is helpful in case you ever
need to rewind data.
DECLARE @TempTableToHoldIDs table( ID int,
DeletedFirstName varchar(50),
InsertedFirstName varchar(50));
UPDATE FirstNames
SET FirstName = 'Billy'
OUTPUT INSERTED.ID,
DELETED.FirstName,
INSERTED.FirstName,
INTO @TempTableToHoldIDs
WHERE FirstName = 'Bill'
Select * from @TempTableToHoldIDs
--Returns 1, Bill, Billy