Solved

Multiple select results in trigger

Posted on 2013-01-13
3
644 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 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Creating and Managing Databases with phpMyAdmin in cPanel.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

861 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

25 Experts available now in Live!

Get 1:1 Help Now