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 |
|
maevr
Posting Yak Master
169 Posts |
Posted - 2008-11-07 : 08:52:32
|
| When I delete a row from table1 I want the referencing rows to be deleted in table2, how can I manage this using a trigger?table1x int primary keyval char(50)primary key(x)table2p int identity(1,1)val2 char(50)table1_x referencing table1(x)primary key(p) |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-07 : 09:06:57
|
the best way to do this is to give ON DELETE CASCADE option while definning the foreignkey constraint in table2.this will make sure deletion will happen automaticallyAnd if you want to do it by means of triggerCREATE TRIGGER YourTriggerON table1AFTER DELETEASDELETE tFROM table2 tINNER JOIN DELETED dON d.x=t.table1_xGO |
 |
|
|
|
|
|