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 |
|
fares47
Starting Member
2 Posts |
Posted - 2011-11-26 : 10:10:21
|
| Hi every body i want to create a trigger for insertion cascade in other words i have for example 2 tables T1 and T2 that have relationship between them and each table have a structure like this : T1(idstud(pk),name,age) T2(idstud(fk),grade,...)and when i insert a new row in T1 the trigger will be able to add same idStud to T2 (just idStud) Thanks in advanceI Want to believe in what i know |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-26 : 10:19:42
|
it will be likeCREATE TRIGGER InsertT2DataON T1FOR INSERTASBEGININSERT T2SELECT idstud,grade,..FROM INSERTEDEND I would have handled this in insert procedure itself though to improve maintainability------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
fares47
Starting Member
2 Posts |
Posted - 2011-11-26 : 11:27:37
|
| Thanks but when Trigger is fired and i have a little surprise :when i run select against T2 it display idStud twice for example when i add idStud =1 to table T1 trigger add twice the same value :T1 ------ idStud ------ 1T2 ------ idStud ------ 1 1I don't understand why ?!I Want to believe in what i know |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-26 : 12:17:50
|
quote: Originally posted by fares47 Thanks but when Trigger is fired and i have a little surprise :when i run select against T2 it display idStud twice for example when i add idStud =1 to table T1 trigger add twice the same value :T1 ------ idStud ------ 1T2 ------ idStud ------ 1 1I don't understand why ?!I Want to believe in what i know
can you show your insertion code?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|