Reputation: 521
The question is about Sqlite DBMS.
I have two tables:
How to write an INSERT and UPDATE triggers for table 2 to check for circular dependencies?
Example of objects dependencies:
A -> B -> C --- ok
A -> B -> C -> A --- raise condition
I understand how to check the immediate dependency A -> B, but have no idea how to check for any level.
Upvotes: 0
Views: 930
Reputation: 185922
You're pushing the proverbial uphill.
One fairly simple solution, which may or may not be feasible in your circumstances, is to have a constraint on the second table: id > id_parent
. This will make it impossible to create cyclic graphs:
CREATE TABLE deps ( id NOT NULL, id_parent NOT NULL, CHECK ( id > id_parent ) )
Upvotes: 1