Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multiple select results in trigger

Posted on 2013-01-13
3
Medium Priority
?
689 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
3 Comments
 
LVL 12

Accepted Solution

by:
Saurabh Bhadauria earned 1500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ready to get certified? Check out some courses that help you prepare for third-party exams.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

972 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