473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Update Trigger - Update Query

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
1 2186

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: pg | last post by:
Is there any simple way to query the most recent time of "changes" made to a table? I'm accessing my database with ODBC to a remote site thru internet. I want to eliminate some DUPLICATE long...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
6
by: Robert Fitzpatrick | last post by:
On 7.4.2 I have a trigger that I want to update any existing boolean values to false if a new one in that group is declare true by inserting a new record or updating an existing record: ohc=#...
0
by: Robert Fitzpatrick | last post by:
I have a trigger that performs an UPDATE query on the same table that the Update trigger is defined. Of course, it loops infinitely, is there a way to do this? CREATE OR REPLACE FUNCTION...
2
by: Dima Gofman | last post by:
I have a trigger on UPDATE on a table. I'm running some maintenance UPDATE and DELETE queries which I want the trigger to ignore but at the same time I want other UPDATE queries that other users...
1
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
4
by: Joerg Gempe | last post by:
Hello, I've a problem where some data gets updated but I don't know which process (SP) is responsible for it (it's an old installation which I've taken over). Is it somehow possible to know...
0
by: magnolia | last post by:
i created a trigger that will record the changes made to a table .everything works fine except the insert query.whenerever i try to insert a record it fires insert and update triger at the same time...
13
by: Neil | last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been running for 20 minutes so far! The query is quite simple: update a single field in a table, based on a join with another...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.