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 |
|
abarsami
Yak Posting Veteran
68 Posts |
Posted - 2001-01-17 : 20:39:22
|
| I need to create a trigger that will do a cascaded delete throughout 1 table.Let's say 1 table has a Primary_key column. It also has a foreign_key column that refers to the primary_key column in that table.I want to be able to delete the table by saying.Delete table1 where primary_key = XSo it first goes and deletes any rows that have foreign keys the same as the primary key.After it has finished all of that, then it can go ahead and delete table1 where primary_key = X.Ex:Table1primary_key foreign_key___________ ____________1 NULL2 13 14 35 2So if I say Delete Table1 where primary_key=1It first deletes all the rows with a foreign_key of 1, then also deletes rows 4 and 5, because they are foreigned key to columns 2 and 3. Finally it deletes row 1. |
|
|
|
|
|