Solved

Help with Trigger

Posted on 2015-01-14
5
102 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
  • 3
  • 2
5 Comments
 
LVL 69

Accepted Solution

by:
ScottPletcher 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:ScottPletcher
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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 retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now