Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Triggers and procedures

Author  Topic 

forrestgump
Starting Member

19 Posts

Posted - 2013-02-12 : 04:57:23
Not sure if I am asking the right question but would it be possible to run the below code so when information in my tables is updated the code below automatically runs?

DELETE FROM Funnel;

INSERT INTO funnel
SELECT [Q2_MetMin].*
FROM Q2_MetMin;

INSERT INTO funnel
SELECT [Q3_RecApp].*
FROM Q3_RecApp;

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-12 : 05:01:49
yep.. you can add this code in a procedure and call it from scheduled sql agent job. the preceding step should be the one which updates information in your tables. The job can then be scheduled as per your required schedule

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2013-02-12 : 05:35:18
>> when information in my tables is updated the code below automatically runs?

Yes it would be a trigger.
What do you want to fire the trigger though?
I'm guessing it would be an update to Q2_MetMin or Q3_RecApp? That might mean a trigger on each of those tables.
This might be an issue because if someone does single row updates then the data in funnel would be deleted and inserted for each row.
You might want to consider a trigger that uses the PK of the row updated in the source tables to minimise the activity.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

forrestgump
Starting Member

19 Posts

Posted - 2013-02-12 : 09:37:10
Yes I would want the updates in Q2_MetMin to fire the trigger. How do I write the correct syntax?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-12 : 09:50:31
quote:
Originally posted by forrestgump

Yes I would want the updates in Q2_MetMin to fire the trigger. How do I write the correct syntax?



CREATE TRIGGER YourTrggerName
ON Q2_MetMin
FOR UPDATE
AS
BEGIN
...your code
END


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

forrestgump
Starting Member

19 Posts

Posted - 2013-02-12 : 10:39:04
Thanks visakh and nigel
Go to Top of Page
   

- Advertisement -