How to get the values that have been updated?
For example: to get the values to create a Trigger that have been passed with INSERT command the following can be done:
SELECT @pid=Product_ID, @q=Item_Quantity, @invid=Invoice_ID FROM Inserted
So, I would have access to the values that have been passed with INSERT comma开发者_如何学运维nd and use them in SQL Server in my Trigger. What would be the equivalent for UPDATE commands? How would I get the values that I will pass from my program to SQL Server through UPDATE commands? Something like below gives me an error:
SELECT @pid=Product_ID, @q=Item_Quantity, @invid=Invoice_ID FROM Updated
You need to use the combination of Inserted and Deleted to know what is updated. For each row that is updated, the original values will appear in Deleted and the new values will be in Inserted.
So, if you just want to get the new values from your UPDATE, you could use the same query as the one used for INSERT.
精彩评论