Solved

Multiple select results in trigger

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MS SQL Backup 24 70
Complex SQL 10 33
SQL JOIN 6 35
How to return the value of the integer variables used in the stored procedure 3 33
Creating and Managing Databases with phpMyAdmin in cPanel.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

757 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

21 Experts available now in Live!

Get 1:1 Help Now