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 |
Gerald30
Yak Posting Veteran
62 Posts |
Posted - 2012-09-26 : 05:20:19
|
Hello All,I really need some help on how to create triggers in MS SQL.Previously we are using MySQL and now we need to migrate to MS SQL.Can some one teach me on how to create triggers in MSSQL?I have a made a trigger that do thisTableA and Table B.If I insert Name and Age to Table A it automatically creates a copy to Table B.I have use this syntax.create trigger tig1 on TableAfor insert asinsert into TableB(name2,age2) select name,age from insertedgo Now next thing that I want to do is when you update the Name or Age in TableA it will also update in TableB.I will really appriciate any of your help.Thank you. |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-26 : 05:25:01
|
Is there a key column to match rows from tableA with tableB? Too old to Rock'n'Roll too young to die. |
|
|
Gerald30
Yak Posting Veteran
62 Posts |
Posted - 2012-09-26 : 20:55:45
|
Oh Sorry I forgot to include the EID.TableA hase EID,Name,Age while be TableB has EID2,Name2 and Age2 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-27 : 02:35:45
|
create trigger tig2 on TableAfor update asupdate t2set name2 = i.name, age2 = i.agefrom TableB as t2 join inserted as i on i.EID = t2.EID2go Too old to Rock'n'Roll too young to die. |
|
|
|
|
|