03 Mei 2012

How to Save Data that Already Deleted To New Table

Using Syntax Output Deleted and Inserted,
- Untuk menyimpan data yang dihapus pada satu table baru

-----start-----
---Declaration
DECLARE @ProductChanges TABLE
 (DeletedName nvarchar(50)
 ,InsertedName nvarchar(50)
 )

---Update column Name
UPDATE SalesLT.Product
SET
 Name='TEST UPDATE - HL Road Frame - Black, 58'
OUTPUT
 DELETED.Name,
 INSERTED.Name
INTO @ProductChanges
WHERE ProductID = 680

---Display after changes
SELECT * FROM @ProductChanges
-----end-----