Solved

Help with Trigger

Posted on 2015-01-14
5
112 Views
Last Modified: 2015-01-15
I need a trigger that will update a table with values inserted into another table.

Say an insert is done to table "A".  This table has some data columns and a FK column to table "B".   Upon insert, I want to update table "B" using the FK in a WHERE clause and setting 3 other data columns, all of which exist in both tables.
0
Comment
Question by:HLRosenberger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 40550097
CREATE TRIGGER A_TRG_INSERT
ON A
AFTER INSERT
AS
SET NOCOUNT ON
UPDATE B
SET col1 = i.col1,
       col2 = i.col2,
       col3 = i.col3
FROM inserted i
INNER JOIN B ON
    B.B_key = i.B_key
GO
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 40551014
I got it working.  thanks,.
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 40551434
I've requested that this question be closed as follows:

Accepted answer: 0 points for HLRosenberger's comment #a40551014

for the following reason:

I got it working.  thanks,.
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 40551435
I provided a working example of how to use the inserted table in a trigger to join to and update a different table.  I believe that had to be of some value in coding such a trigger.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 40551475
Sorry.  I meant to accept your solution.

I got it working.  thanks,.
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question