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 |
sqlhunter123
Starting Member
2 Posts |
Posted - 2008-01-14 : 08:41:49
|
Hi I have two tables A and B. Table A has a foreign key which refers to primary key of Table B. Table B has a reference to table A using a field LastAid which refers to primary key Of A. Both these relations have no cascade on delete set.My problem is I have to delete some data from table A. But the constraint on LastAid in table B does not allow me to delete the data. How can I do this? Please help me.....Thanks in advance... |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-14 : 10:48:39
|
create a instead of delete trigger on A which deletes all reffering columns in B referring to A and then delete A's records.Something like this.something like:-CREATE TRIGGER MyTriff ON TableAINSTEAD OF DELETEASDELETE a FROM TableA aINNER JOIN TableB bON b.LastAid=a.LastAidINNER JOIN DELETED dON d.ForKeyA=b.PrimKeyDELETE bFROM TableB bON b.LastAid=a.LastAidINNER JOIN DELETED dON d.ForKeyA=b.PrimKeyBDELETE a FROM TableA aINNER JOIN DELETED dON d.prmkeyA=a.PrimkeyAGO |
 |
|
|
|
|