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.
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 funnelSELECT [Q2_MetMin].*FROM Q2_MetMin;INSERT INTO funnelSELECT [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 MVPhttp://visakhm.blogspot.com/ |
|
|
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. |
|
|
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? |
|
|
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 YourTrggerNameON Q2_MetMinFOR UPDATEASBEGIN...your codeEND ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
forrestgump
Starting Member
19 Posts |
Posted - 2013-02-12 : 10:39:04
|
Thanks visakh and nigel |
|
|
|
|
|