By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

Update Trigger - Update Query

P: n/a
Hi there,

I'm a little stuck and would like some help

I need to create an update trigger which will run an update query on
another table.

However, What I need to do is update the other table with the changed
record value from the table which has the trigger.

Can someone please show me how this is done please??

I can write both queries, but am unsure as to how to get the value of
the changed record for use in my trigger???

Please help

M3ckon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"m3ckon" <an*******@devdex.com> wrote in message
news:41**********************@news.newsgroups.ws.. .
Hi there,

I'm a little stuck and would like some help

I need to create an update trigger which will run an update query on
another table.

However, What I need to do is update the other table with the changed
record value from the table which has the trigger.

Can someone please show me how this is done please??

I can write both queries, but am unsure as to how to get the value of
the changed record for use in my trigger???

Please help

M3ckon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


I'm not entirely sure, but I guess you want something like this:

create trigger MyTrig on MyTable
after update
as
begin
if @@rowcount = 0 return

update dbo.MyTable2
set col1 = i.col1
from inserted i
join dbo.MyTable2 mt
on i.PrimaryKey = mt.PrimaryKey
end

This assumes that MyTable2 has the same primary key as MyTable. Another
possibility to consider might be cascading referential integrity, if that's
appropriate for your situation - see Books Online.

If this doesn't help, please post the full CREATE TABLE statements for both
tables.

Simon
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.