I have 2 tables, "TableA" and "TableB" setup like below.
Table A
+----------+------+---------------+ | StreamID | Name | Other Columns | +----------+------+---------------+
Table B
+----+--------------+------------------------+-----------+ | ID | FileStreamID | AdditionalFileStreamID | DateAdded | +----+--------------+------------------------+-----------+
Both FileStreamID and AdditionalFileStreamID in Table A are foreign key constraints to the StreamID column in Table B. I tried setting up the constraint on both columns so that when the row in Table A is deleted, the 2 columns are both set to NULL, however got a 'multiple cascade paths' exception (similar issue below):
2 foreign key to the same table may cause cycles or multiple cascade paths
Instead, I tried creating the following trigger to handle it:
CREATE TRIGGER dbo.File_Deletion_Trigger
ON dbo.TableA
INSTEAD OF DELETE
AS BEGIN
UPDATE dbo.TableB
SET FileStreamID = NULL
WHERE FileStreamID IN (SELECT d.StreamID FROM deleted d)
UPDATE dbo.TableB
SET ScheduleStreamID = NULL
WHERE AdditionalFileStreamID IN (SELECT d.StreamID FROM deleted d)
DELETE FROM dbo.TableA
WHERE StreamID IN (SELECT d.StreamID FROM deleted d)
END
GO
I am getting the following exception when I try to create the trigger:
Msg 195, Level 15, State 10, Procedure TableA, Line 1 [Batch Start Line 0]
'getfileextension' is not a recognized built-in function name.
Msg 474, Level 16, State 0, Procedure File_Deletion_Trigger, Line 6 [Batch Start Line 0]
Unable to load the computed column definitions for table "deleted".
Does anyone know why this might be happening?