I have a problem when it comes to making a few tables for tables and I hope they can help me.
Let's imagine that I have a Grandfather table created in the following way:
CREATE TABLE ABUELO{
IDABUELO INT PRIMARY KEY
}
And a Father
table CREATE TABLE PADRE{
IDPADRE INT PRIMARY KEY
IDABUELO INT CONSTRAINT FK_IDABUELO FOREIGN KEY IDABUELO REFERENCES ABUELO(IDABUELO) ON DELETE CASCADE
}
The Father table is referenced to Grandpa's by IDABUELO .
Now, I also have a Son table declared in the following way.
CREATE TABLE HIJO{
IDHIJO INT PRIMARY KEY
IDPADRE INT CONSTRAINT FK_IDPADRE FOREIGN KEY IDPADRE REFERENCES PADRE(IDPADRE ) ON DELETE CASCADE
}
Which is this reference to Father by its IDPADRE code.
Besides these, I have a blog tables ABUELO_Log , PADRE_Log , and HIJO_Log that have the same attributes.
When I delete a row of Grandpa , being ON DELETE CASCADE, the parents that have the code referenced to that grandfather will be deleted. Once, all the children that have their code referenced to father are deleted.
The problem is to make an AFTER DELETE Trigger (it can not be INSTEAD OF) that saves the record of the deleted row in its respective logbook table.
When the Grandfather row is deleted, I can recover the deleted data from the temporary table DELETED accessible during the trigger, and transfer this data to ABUELO_Log .
But, where are the deleted data of Father and Son saved to recover them and save them in their respective bitacoras?
Are they stored in the same DELETED table, or are several DELETED tables created according to the deleted tables?
I know how to do this problem with an INSTEAD OF trigger, but the problem requires an AFTER trigger.