I am trying to figure out how to perform on update cascade on a self-referencing temporal table using triggers. While I found that this post (On delete cascade for self-referencing table) is the closest it can get to my answer, I had the below questions:
The Answer and the question seems incomplete in the post. Can you please tell me what is contained in Deleted
table in the post? What is id
in Deleted
table and Comments
table? Is it a primary key? What if primary key is a pair of columns? Also, I am not sure why is IDs inside the CTE IDs. Seems incorrect. I am not sure.
What would the on update cascade specific trigger look like if the table has other foreign key constraints?
I have the below table setup. Can you please help me create a trigger for it on update cascade on the foreign key FK_Son_Height_Weight? I could use a surrogate key here but there are several tables that have foreign key reference to PK_Height_Weight. Is there a way to make sure I dont need a surrogate key?
(Note: the table has been modified for privacy reasons)
CREATE TABLE no.Man (
Height varchar(100) NOT NULL,
Weight varchar(50) NOT NULL,
CONSTRAINT PK_Height_Weight PRIMARY KEY (Height, Weight),
CONSTRAINT FK_Weight FOREIGN KEY (Weight)
REFERENCES no.Human (Weight)
On Update Cascade,
Son_Height varchar (100) NOT NULL,
Son_Weight varchar (50) NOT NULL,
CONSTRAINT FK_Son_Height_Weight FOREIGN KEY (Son_Height, Son_Weight)
REFERENCES no.Man(Height,Weight)
On Update Cascade
)