SQL - recursion statement (trigger)

谁都会走 提交于 2020-01-04 13:37:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!