Request to write and explain the operation of a trigger that will first update the parent table TAB1 (update in the code) and then TAB2. I get this error:
ERROR: SQL ERROR [23504]: THE PARENT KEY IN A PARENT ROW OF RELATIONSHIP "TAB2.TAB2_FK" CANNOT BE UPDATED.. SQLCODE=-531, SQLSTATE=23504, DRIVER=4.25.13
Code:
CREATE TABLE TAB1
(
ID INTEGER PRIMARY KEY NOT NULL,
SOMETHING VARCHAR(100) NULL
);
CREATE TABLE TAB2
(
ID INTEGER PRIMARY KEY NOT NULL,
TAB1_ID INTEGER NOT NULL
);
ALTER TABLE TAB2
ADD CONSTRAINT TAB2_FK
FOREIGN KEY (TAB1_ID) REFERENCES TAB1(ID);
INSERT INTO TAB1 (ID, SOMETHING) VALUES (1, 'XYZ');
INSERT INTO TAB1 (ID, SOMETHING) VALUES (2, 'ABC');
INSERT INTO TAB2 (ID, TAB1_ID) VALUES (1, 1);
UPDATE TAB1
SET ID = 5
WHERE ID = 1;
TAB1andINSTEAD OF UPDATEtrigger on it to run the lastUPDATEon this view, not on the base tableTAB1. Otherwise it's not a singleBEFORE UPDATEtrigger onTAB1withINSERT INTO TAB2of rows with a newTAB1_ID(and generation of new PK values somehow for them), but with an additionalAFTER UPDATEtrigger onTAB1withDELETE FROM TAB2of rows with oldTAB1_ID...