Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to Update Multiple rows using triggers

Author  Topic 

nandithab
Starting Member

6 Posts

Posted - 2008-02-11 : 05:01:51
I have a trigger
to update multiple rows.But the trigger will fire only on the last row that is being updated .I need to make a trigger that fires for ALL the records that are being updated into a particular table.
For example:

Table BOOK:
id -PK for BOOK table
author
title
year

Table MODIFIEDBOOK
id-FK to MODIFIEDBOOK table
action

On updating the PK of Parent table ie.,BOOK,it has to update the FK of child table MODIFIEDBOOK with the corresponding updated id.

The trigger which i created on BOOK table,checks for any update that is performed on the BOOK table and it updates the child table MODIFIEDBOOK with the respective new id s.


But the trigger fires only for the last updated value in Parent Table Book.
I want that to fire for every updated row in parent table...

How can i do this?.

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-02-11 : 05:06:30
Why you want to use a trigger?
You can set the cascade property for update in relationship for the key columns.
Go to Top of Page

nandithab
Starting Member

6 Posts

Posted - 2008-02-12 : 04:36:35
if i use cascade property to those tables,then it forms concurrent relations between those tables(actually there is another tables linked to this.So it forms concurrent relations between 3 tables)...and cascade property fails in this situation..only option is to use trigger to update in child table...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-12 : 07:14:58
Similar to this?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=97197

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

nandithab
Starting Member

6 Posts

Posted - 2008-02-12 : 07:50:03
ya
Go to Top of Page
   

- Advertisement -