In the minimal reproducible example below, table C is invalid as it results in a cycle. I understand I can simplify C by removing the constraints, however the number of triggers required after goes up significantly if I want to preserve the cascading behavior from anywhere in the hierarchy (the actual use case more tables).
Based on the documentation, there are no foreign key constraints other than NO ACTION allowed on a table with an INSTEAD OF DELETE which would result in an error.
I would prefer not to split table B, but the actual use case is a lot larger and complex and it looks like I'd have to make all the foreign keys plain columns without references, and implement referential integrity manually.
Is the truly the only way?
CREATE TABLE A
(
Id UNIQUEIDENTIFIER NOT NULL DEFAULT (newsequentialid()) PRIMARY KEY,
Name NVARCHAR(256) NOT NULL
);
CREATE TABLE B
(
Id UNIQUEIDENTIFIER NOT NULL DEFAULT (newsequentialid()) PRIMARY KEY,
AId UNIQUEIDENTIFIER NOT NULL,
Name NVARCHAR(256) NOT NULL,
CONSTRAINT FK_B_A FOREIGN KEY (AId) REFERENCES A (Id) ON DELETE CASCADE
);
CREATE TABLE C
(
Id UNIQUEIDENTIFIER NOT NULL DEFAULT (newsequentialid()) PRIMARY KEY,
PrimaryId UNIQUEIDENTIFIER NOT NULL,
SecondaryId UNIQUEIDENTIFIER NOT NULL,
CONSTRAINT FK_C_PrimaryId FOREIGN KEY (PrimaryId) REFERENCES B (Id),
CONSTRAINT FK_C_SecondaryId FOREIGN KEY (SecondaryId) REFERENCES B (Id)
);