Solved

Multiple select results in trigger

Posted on 2013-01-13
3
660 Views
Last Modified: 2013-01-13
I am using sql-server 2005.

I am writing a trigger for table A.

When table A is updated, i wish to record in table Y data from rows in table B which reference the primary key for table A. (i.e.: there is a column in table b which has a foreign key which references table A. I need data from all the rows which have this foreign key in it)

Is this possible (and how would I do it)?

Can I write a loop within the trigger which runs for each row of a select query?
0
Comment
Question by:rdun25
[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 Comments
 
LVL 12

Accepted Solution

by:
Saurabh Bhadauria earned 500 total points
ID: 38773302
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38773331
yes you can.

but what is your eaxtact requirment ?

You want to update table Y riws from table B with Ref in Table A.
can you give some sample data so that we can help you in creatinmg trigger
trigger can be wriiten like this

CREATE TRIGGER Whatever ON TableName AFTER UPDATE
AS
BEGIN
    IF UPDATE(B)
    BEGIN
        /* Update column C here */
    END
END
0
 

Author Comment

by:rdun25
ID: 38773380
Thanks for your help, those are great articles, solved my problem.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

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…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

730 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