2

Consider a trigger after update on the table A. For every update the trigger should update all the records in table B. Then consider this query:

UPDATE A SET X = Y 

Apparently there are many rows updated. After the update the trigger takes place. Now if the trigger would be using inserted table, and you would like to update the table B with every single row of the temporary table inserted, and in MSDN is not recommended to use cursors, how would you do that?

Thank you

1
  • You need to post the structure of both tables and how they relate to each other in order to get an accurate answer. Commented Jun 27, 2010 at 18:16

2 Answers 2

4

I don't know what exactly you want to do in your update trigger, but you could e.g.

UPDATE dbo.B
SET someColumn = i.Anothervalue
FROM Inserted i
WHERE b.Criteria = i.Criteria

or something else - you need to tell us a bit more about what it is you want to do with table B! But it's definitely possible to update, insert into or other things, without using a cursor and handling multiple rows from the Inserted table.

Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I wanted to know.. i can match it with all rows from the inserted table.
1

I will assume that table A is related to table B via a key (have to assume, as you posted no details).

If that is the case, you can use either sub-queries or joins with inserted to select the rows that need changing on table B.

UPDATE tableB B
SET B.colx = someValue
WHERE B.id IN
(
    SELECT b_id 
    FROM INSERTED
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.