I have a table that has a autoreference relationship, like that:
TableA(IDTableA, IDTableARoot,...)
and I have this instead of delete trigger to delete:
Delete from TableA where IDTableARoot IN(select deleted.IDTableA from deleted)
Delete from TableA where IDTableA IN(select deleted.IDTableA from deleted)
I guess that I have this two rows:
Row 1: IDTableA: 1 IDTableARoot: 1
Row 2: IDTableA: 2 IDTableARoot: 1
When I try to delete the row 1:
delete from TableA where IDTableA = 1;
Only it is deleted the row with ID = 1, but not the row with ID = 2, but it shuld be deleted bacuse in the first statement of the trigger I say that I it has to be deleted the row with IDTableARoot = IDTableA where IDTableA is the ID of the row that I am deleting.
So, how could I delete in cascade rows that belong to a self relationship?
Thank you so much.