Solved

Help with Trigger

Posted on 2015-01-14
5
117 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

728 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