Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping 2 fields values the same across 2 tables after update

Status
Not open for further replies.

webmasternts

Programmer
Joined
Dec 14, 2001
Messages
1
Location
US
Does anyone have any suggestions on how to wright a trigger on a update that would keep 2 fields in 2 seperate tables in sync.

example:
Table 1 has a field called sent
Table 2 has a table called sent

When table 1 sent gets updated the update trigers fires and writes the value in table 1 sent to table 2 sent Any help would keep my job thanks
 
Hi there.
You can make use of SQL's special Inserted table for this trigger. This is a temporary, memory-resident table that contains all of the data from the record currently being inserted/updated. Here is an example of how to write a trigger using this table (I used "myid" to represent the primary and foreign keys in each of your tables):

create trigger tr_UpdateSent on table1
for update
as

update table2
set sent = i.sent
from inserted i inner join
table2 t on
i.myid = t.myid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top