August 30, 2010 at 2:56 pm
How trigger works on update statement affecting more than one row?
August 30, 2010 at 3:18 pm
vrkn82 (8/30/2010)
How trigger works on update statement affecting more than one row?
If coded properly as a set-based operation, just fine.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
August 30, 2010 at 5:30 pm
inserted and deleted tables hold the changed data as a result set, not a single row.
Avoid the following code as it won't handle multiple updates.
DECLARE @insertedValue VARCHAR(10), @insertedID VARCHAR(10), @deletedValue VARCHAR(10), @deletedID VARCHAR(10)
SELECT @deletedValue = DeletedValue, @deletedID = DeletedID
FROM deleted
SELECT @insertedValue = InsertedValue, @insertedID = InsertedID
FROM inserted
then use the variable in your insert/delete/update statements.
Just insert, delete, and/or update as you would with multiple tables, not variables.
August 30, 2010 at 8:41 pm
How do i know that no of records updated without seeing the table ?
in one transaction 1 record or multiple records can be updated.
Is there any way finding out this ?
Thank you
August 30, 2010 at 9:34 pm
You could do a select count(*) from inserted within the trigger.
Alternatively, in the code running the update statement, look at @@rowcount.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply