问题
I've got this problem with this excercice:
Table Friend
Friend1 Friend2
Table Relationship
Friend1 Friend2 GradeOfFriendship
So, i need to create a trigger system that make symmetric tuple after delete, insert update for example
insert into Friend values('Luc' ,'Mark')
my trigger system must insert into the table Friend the following value
Mark Luc
So i've symmetric tuple. But is not my real problem after insert, update, delete on table friend i must have another trigger that works only on the table Relationship and do the same things: 1) Insert the direct couple of friend with GradeOfFriendship = 1 2) Search the minimum path before other couple of friends for example
Luc Marc 1
Marc John 1
Luc John 2
i've got a direct relationship between Luc and Marc so i insert into the table of relationship 1, i've got the same thing on Marc and John and i do the same thing, but Luc at the moment don't have any path with John, we can build it with the common friend Marc so the lenght of this path will be (1+1 = 2)
if i don't have any contact with a people (so i don't have friend in common) GradeOfFriendship = 0
I trying with SQL Server but at the moment i don't have any idea to how do this statement, i think that i must use some recursive function but i don't know how....
来源:https://stackoverflow.com/questions/30968178/sql-recursion-statement-trigger